Q: What will be the output of the following program?
class A
{
public int i;
protected int j;
}
class B extends A
{
int j;
void display()
{
super.j = 3;
super.i = 10;
System.out.println(super.i + " " + super.j);
System.out.println(i + " " + j);
}
}
class Output
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
A: 10 3 10 2
Q: The closest common ancestor of RuntimeException, Error, IOException, and ClassNotFoundException is:
A: Throwable
Q: Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
A: super();
Q: If super class and subclass have the same variable name, which keyword should be used to use super class?
A: super
Q: What will be the output of the following 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: Compile Time Error
Q: A class member declared protected becomes a member of a subclass of which type?
A: private member
Q: What will be the output of the following 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
Q: What will be the output of the following program?
class A {
public int i;
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
System.out.println(super.i + " " + super.j);
}
}
class inheritance {
public static void main(String args[]) {
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
A: Compile Time Error
Q: If there are 5 classes, E is derived from D, D from C, C from B, and B from A. Which class constructor will be called first if an object of type E or D is created?
A: A
Q: Which of the following is used for implementing inheritance through classes?
A: extends
Q: Which of the following, Multiple inheritance in Java can be implemented?
A: Interfaces
Q: Which of these is the correct way of inheriting class A by class B?
A: class B extends A {}
Q: In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
A: Private
Q: What would be the result if a class extended two interfaces, both of which have a method with the same name and signature?Let's assume that the class is not implementing that method.
A: Compile time error
Q: Which of these methods of the Object class can clone an object?
A: Object clone()