Font size
WorksheetsInheritance Java
Total questions: 132
Worksheet time: 29mins
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
Inheritance means
Sub class extends Base class
Sub class extends super class
Sub class create object of super class
All of the above
What type of inheritance does Java have?
Single Inheritance
Double Inheritance
Multiple Inheritance
Class Inheritance
Which of this keyword must be used to inherit a class?
extends
extent
super
this
What is not type of inheritance?
Single Inheritance
Double Inheritance
Multiple Inheritance
Class Inheritance
What are the features reused using Inheritance in Java?
Variables
Constants
Methods
All the above
Which inheritance in java programming is not supported?
Single inheritance
Multilevel inheritance
Multiple inheritance using classes
Multiple inheritance using interfaces
A ........... is a group of objects which have common properties.
Class
Sub Class
Super Class
None
.............. is a class which inherits the other class.
Class
Sub Class
Super Class
None
................. is the class from where a subclass inherits the features.
Class
Sub Class
Super Class
None
Subclass is also called a ...........
Derived Class
Extended Class
Child Class
All the above
Superclass is also called a ...............
Base Class
Parent Class
Both A and B
None
is an example of
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
None
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
When an object's class is a subclass of a more general class.
Extension
Aggregation
Inheritance
Dependency
Which Java statement represents inheritance?
class body inherit Car
class body super Car
class body extends Car
class body this Car
class body override Car
Which of the following is/are false about inheritance in Java?
I. A subclass inherits all the methods and variables of the superclass.
II. A subclass can override the methods of its superclass
III. A subclass has access to the private instance variables of the superclass.
I only
II only
III only
I and II only
I and III only
super keyword is used to access
only subclass methods
parent class variables and methods
subclass variables and methods
only parent class methods
What is the output of following Java Program?
class Online
{
public
void print()
{
System.out.println("Online::print() called");
}
}
class OOP extends Online
{
public
void print()
{
System.out.println("OOP::print() called");
}
}
public class Main
{
public static void main(String[] args)
{
OOP ob =new OOP();
ob.print();
}
}
Online::print() called
OOP::print() called
Consider the following code.
class Vehicle
{
int maxSpeed = 120;
}
class Car extends Vehicle
{
int maxSpeed = 180;
void display() {
System.out.println("Maximum Speed: " + super.maxSpeed);
}
}
/* Driver program to test */
class Test
{
public static void main(String[] args)
{
Car small = new Car(); small.display();
}
}
In the program output, what is the maximum speed displayed?
120
180
120 dan 180
semua salah
