Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //10. Analyze the following code:
- public class Test {
- public static void main(String[] args) {
- new B();
- }
- }
- class A {
- int i = 7;
- public A() {
- setI(20);
- System.out.println("i from A is " + i);
- }
- public void setI(int i) {
- this.i = 2 * i;
- }
- }
- class B extends A {
- public B() {
- // System.out.println("i from B is " + i);
- }
- public void setI(int i) {
- this.i = 3 * i;
- }
- }
- //a. The constructor of class A is not called.
- //b. The constructor of class A is called and it displays "i from A is 7".
- //c. The constructor of class A is called and it displays "i from A is 40".
- //d. The constructor of class A is called and it displays "i from A is 60".
- //Key:d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement