Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. //45. The getValue() method is overridden in two ways. Which one is correct?
  2.  
  3. //I:
  4. public class Test {
  5.   public static void main(String[] args) {
  6.     A a = new A();
  7.     System.out.println(a.getValue());
  8.   }
  9. }
  10.  
  11. class B {
  12.   public String getValue() {
  13.     return "Any object";
  14.   }
  15. }
  16.  
  17. class A extends B {
  18.   public Object getValue() {
  19.     return "A string";
  20.   }
  21. }
  22.  
  23. //II:
  24. public class Test {
  25.   public static void main(String[] args) {
  26.     A a = new A();
  27.     System.out.println(a.getValue());
  28.   }
  29. }
  30.  
  31. class B {
  32.   public Object getValue() {
  33.     return "Any object";
  34.   }
  35. }
  36.  
  37. class A extends B {
  38.   public String getValue() {
  39.     return "A string";
  40.   }
  41. }
  42.  
  43. //a. I
  44. //b. II
  45. //c. Both I and II
  46. //d. Neither
  47. //Key:b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement