Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. //10. Analyze the following code:
  2.  
  3. public class Test {
  4.   public static void main(String[] args) {
  5.     new B();
  6.   }
  7. }
  8.  
  9. class A {
  10.   int i = 7;
  11.   public A() {
  12.     setI(20);
  13.     System.out.println("i from A is " + i);
  14.   }
  15.  
  16.   public void setI(int i) {
  17.     this.i = 2 * i;
  18.   }
  19. }
  20.  
  21. class B extends A {
  22.   public B() {
  23.     // System.out.println("i from B is " + i);    
  24.   }
  25.  
  26.   public void setI(int i) {
  27.     this.i = 3 * i;
  28.   }
  29. }
  30.  
  31. //a. The constructor of class A is not called.
  32. //b. The constructor of class A is called and it displays "i from A is 7".
  33. //c. The constructor of class A is called and it displays "i from A is 40".
  34. //d. The constructor of class A is called and it displays "i from A is 60".
  35. //Key:d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement