Java - Method overridin
b
What is the output of this program? class A { int i; public void display() { System.out.println(i); } } class B extends A { int j; public void display() { System.out.println(j); } } class Dynamic_dispatch { public static void main(String args[]) { B obj2 = new B(); obj2.i = 1; obj2.j = 2; A r; r = obj2; r.display(); } } a) 1 b) 2 c) 3 d) 4
a
What is the output of this program? class A { public void display() { System.out.println("A"); } } class B extends A { public void display() { System.out.println("B"); } } class Dynamic_dispatch { public static void main(String args[]) { A obj1 = new A(); B obj2 = new B(); A r; r = obj1; r.display(); r = obj2; r.display(); } } a) A B b) B A c) Runtime Error d) Compilation Error
d
What is the output of this program? final class A { int i; } class B extends A { int j; System.out.println(j + " " + i); } class inheritance { public static void main(String args[]) { B obj = new B(); obj.display(); } } a) 2 2 b) 3 3 c) Runtime Error d) Compilation Error
c
What is the output of this program? advertisements class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class method_overriding { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } a) 0 b) 1 c) 2 d) Compilation Error
b
What is the process of defining a method in subclass having same name & type signature as a method in its superclass? a) Method overloading b) Method overriding c) Method hiding d) None of the mentioned
d
Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B? a) super(void); b) superclass.(); c) super.A(); d) super();
c
Which of these is supported by method overriding in Java? a) Abstraction b) Encapsulation c) Polymorphism d) None of the mentioned
a
Which of these keyword can be used in subclass to call the constructor of superclass? a) super b) this c) extent d) extends
d
Which of these keywords can be used to prevent Method overriding? a) static b) constant c) protected d) final