Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Explain Inheritance.
- * How can you prevent overriding a parent class' method in a child class? (Your answer: static methods.)
- * What is instantiation?
- * How can you instantiate a class in Java?
- class User {
- String name;
- int age;
- User(...) {
- ...
- }
- }
- * What does this do: "User u = new User("Joe", 32);"
- * How does Java "stores" references? (https://youtu.be/mywtIhLnpEU)
- * How does Garbage Collection work in Java?
- * What is pass-by-reference vs pass-by-value? (https://stackoverflow.com/q/40480)
- String a = "hello";
- String b = a;
- int i = 0;
- int j = i;
- foo(a);
- foo(i);
- * What is auto-boxing?
- int i = 1;
- Integer j = 10; // Integer j = Integer.valueOf(10); -> Integer valueOf(int x)
- System.out.prinlnt(i + j); // i + j.intValue() -> int intValue()
- foo(i); // void foo(Integer x);
- bar(j); // void bar(int x);
- * What would happen here?
- Integer j = null;
- bar(j); // void bar(int x);
- bar(j.intValue()); // NPE
- * What does "type-conversion" mean? (Primitive widening/narrowing conversions: https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html)
- String s = ... // user input
- int i = convertUserInputToString(s);
- * What is casting? How does it work? What is the cast operator? (How do you use it?)
- class Animal {
- }
- class Snake extends Animal {
- }
- class Horse extends Animal {
- }
- Animal a = new Animal();
- Horse h = new Horse();
- Snake s = new Snake();
- Animal a1 = h;
- Animal a2 = s;
- public void foo(Animal a) {
- Horse h1 = (Horse)a; // success depends on runtime type of "a"
- }
- foo(new Horse()) // succcess
- foo(new Snake()) // fails: ClassCastException
- * What kind of modifiers do you know about in Java? (public, protected, private, (default), static, final, abstract, synchronized, transient)
- * How can you use the final keyword?
- * Can I modify the value of this array?
- final int[] arr = new int {1, 2, 3];
- ...
- arr[0] = 42; // arr.set(0, 42) (kind of), this won't work
- arr = new int {42, 42, 42}; // this doesn't work
- * When can you initialize a final variable?
- * What is transient?
- * What is synchronized?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement