What will be the output of the following Java program?
class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + ” ” + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
Answer: a
Explanation: Keyword super is used to call constructor of class A by constructor of class B. Constructor of a initializes i & j to 1 & 2 respectively.
output:
1 2
Related Posts
A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be removed?
Circular Queue is also known as ________
A queue follows __________
The data structure required for Breadth First Traversal on a graph is?
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as _____________
Which data structure is used for implementing recursion?
Join The Discussion