No student devices needed. Know more
10 questions
Which of this keyword must be used to inherit a class?
super
this
extends
extent
A class member declared protected becomes a member of subclass of which type?
public member
private member
protected member
static member
class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
0
1
2
Compilation Error
What will be the output of the following Java program?
class A
{
int i;
}
class B extends A
{
int j;
void display()
{
super.i = j + 1;
System.out.println(j + " " + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
2 2
3 3
2 3
3 2
Using which of the following, multiple inheritance in Java can be implemented?
Interfaces
Multithreading
Protected methods
Private methods
In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
Protected
Private
Public
Static
If super class and subclass have same variable name, which keyword should be used to use super class?
super
this
upper
classname
Which inheritance in java programming is not supported
Multiple inheritance using classes
Multiple inheritance using interfaces
Multilevel inheritance
Single inheritance
If class B is subclassed from class A then which is the correct syntax
class B:A{}
class B extends A{}
class B extends class A{}
class B implements A{}
Order of execution of constructors in Java Inheritance is
Base to derived class
Derived to base class
Random order
none
Explore all questions with a free account