1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is inheritance in Java?
A mechanism where one object can inherit properties and behaviors from a parent object, establishing an is-a relationship.
For example: Bike, car, bus this are vehicle.
That's why the child of vehicle are bike, car, bus and vehicle is the parent of this objects.
The 'extends' keyword.
What keyword is used for inheritance in Java?
EX______
Extends
class Parent
//code
class Child e____s Parent
//code
message
display
class super {
Public void display() {
System.out.println("l am parent class");
}
}
class sub extends super {
public static void main(String args[]) {
sub m______ge = new sub()
message.d____y():
}
}
inherits
What is the relationship between a subclass and a superclass?
A subclass ______ the properties and methods of its superclass.
Reusability
reuse
child
Code __________, allowing functions of the parent class to be ________ in the ____ class.
Single
multiple
multi-level
hierarchical
hybrid
What are the types of inheritance in Java?
SMMHH
No, multiple inheritance is not supported in Java.
Is multiple inheritance supported in Java? Yes or No
extends
one
What is single inheritance?
A type of inheritance where a class _______ only ___ other class.
extends
Message_sub message
A cat (subclass) inherits from an animal (superclass).
class message_super {
Public void display() {
System.out.println("l am from superclass");
}
}
class message_sub e____ds message_super {
public static void main(String args[]) {
M______s__ m_____ = new message_sub()
Message.display():
}
}
Multi level inheritance
extends
extends another
Type of inheritance, When a class _______ another class, which in turn e______ a___ class.
Class A is the parent of class B, and class B is the parent of class C.
class a {
int data= 15;
}
class b extends a {
}
class c extends b {
}
public void display() {
System.out.println("number is :" + data);
public static void main(String args[]) {
c num = new c()
num display()
}
}
hierarchical inheritance
A type of inheritance, When one superclass is inherited by multiple subclasses.
Provide an example of hierarchical inheritance.
Class A is the parent class, and classes B and C both inherit from class A.
Class Food{
// code
}
class Rice extends Food{
// code
}
class Fruit extends Food{
// code
}
method overriding
When a method in a child class has the same name and parameters as a method in the parent class. it is called? M______ O_________
No, a final method cannot be overridden.
Can a final method be overridden? yes or no
void
extends
t
class animal {
public ___ display() {
System.out.println("l am animal");
}
}
class tiger e___s animal {
public void display() {
System.out.println("l am tiger");
}
public static void main(String args0) {
tiger __ = new tiger():
display();
}
}
What is the role of the 'super' keyword in Java inheritance?
It is used to refer to the immediate parent class and can be used to call parent class methods.