Join Now
Home Aptitude Reasoning DI VA GK CA CA Hindi Quiz Placements
Single inheritance
Multiple inheritance
Multilevel inheritance
Hybrid inheritance
abstract
final
static
synchronized
finalize()
constructor
main()
start()
interface
implements
extends
override
What is the output of the following program?
class A { int x = 10;}class B extends A { int x = 20;}public class Main { public static void main(String[] args) { A obj1 = new A(); B obj2 = new B(); System.out.println(obj1.x); System.out.println(obj2.x); }}
10, 20
20, 20
10, 10
Compilation error
class A { int x = 10;}class B extends A { int y = 20;}class C extends B { void display() { System.out.println(x + y); }}public class Main { public static void main(String[] args) { C obj = new C(); obj.display(); }}
30
20
10
Abstraction
Polymorphism
Inheritance
Encapsulation
It can be used to access a static field of a class.
It can be used to call a method of a superclass.
It can be used to refer to the current instance of a class.
It can be used to declare a constructor.
this
super