Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. * Explain Inheritance.
  2. * How can you prevent overriding a parent class' method in a child class? (Your answer: static methods.)
  3. * What is instantiation?
  4. * How can you instantiate a class in Java?
  5. class User {
  6. String name;
  7. int age;
  8. User(...) {
  9. ...
  10. }
  11. }
  12. * What does this do: "User u = new User("Joe", 32);"
  13. * How does Java "stores" references? (https://youtu.be/mywtIhLnpEU)
  14. * How does Garbage Collection work in Java?
  15. * What is pass-by-reference vs pass-by-value? (https://stackoverflow.com/q/40480)
  16. String a = "hello";
  17. String b = a;
  18. int i = 0;
  19. int j = i;
  20. foo(a);
  21. foo(i);
  22. * What is auto-boxing?
  23. int i = 1;
  24. Integer j = 10; // Integer j = Integer.valueOf(10); -> Integer valueOf(int x)
  25. System.out.prinlnt(i + j); // i + j.intValue() -> int intValue()
  26. foo(i); // void foo(Integer x);
  27. bar(j); // void bar(int x);
  28. * What would happen here?
  29. Integer j = null;
  30. bar(j); // void bar(int x);
  31. bar(j.intValue()); // NPE
  32. * What does "type-conversion" mean? (Primitive widening/narrowing conversions: https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html)
  33. String s = ... // user input
  34. int i = convertUserInputToString(s);
  35. * What is casting? How does it work? What is the cast operator? (How do you use it?)
  36. class Animal {
  37. }
  38. class Snake extends Animal {
  39. }
  40. class Horse extends Animal {
  41. }
  42. Animal a = new Animal();
  43. Horse h = new Horse();
  44. Snake s = new Snake();
  45.  
  46. Animal a1 = h;
  47. Animal a2 = s;
  48.  
  49. public void foo(Animal a) {
  50. Horse h1 = (Horse)a; // success depends on runtime type of "a"
  51. }
  52. foo(new Horse()) // succcess
  53. foo(new Snake()) // fails: ClassCastException
  54. * What kind of modifiers do you know about in Java? (public, protected, private, (default), static, final, abstract, synchronized, transient)
  55. * How can you use the final keyword?
  56. * Can I modify the value of this array?
  57. final int[] arr = new int {1, 2, 3];
  58. ...
  59. arr[0] = 42; // arr.set(0, 42) (kind of), this won't work
  60. arr = new int {42, 42, 42}; // this doesn't work
  61. * When can you initialize a final variable?
  62. * What is transient?
  63. * What is synchronized?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement