OOP Inheritance

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

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.

2
New cards

The 'extends' keyword.

What keyword is used for inheritance in Java?

EX______

3
New cards

Extends

class Parent

//code

class Child e____s Parent

//code

4
New cards

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():

  }

}

<p><span style="color: rgb(250, 114, 17);">class super</span> {</p><p>Public void display() {</p><p>System.out.println("l am parent class");</p><p>&nbsp; &nbsp;}</p><p>}</p><p><span style="color: yellow;">class sub extends super</span> {</p><p>public static void main(String args[]) {</p><p>sub m______ge = new sub()</p><p>message.d____y():</p><p>&nbsp; }</p><p>}</p>
5
New cards

inherits

What is the relationship between a subclass and a superclass?

A subclass ______ the properties and methods of its superclass.

6
New cards
  • Reusability

  • reuse

  • child

Code __________, allowing functions of the parent class to be ________ in the ____ class.

7
New cards
  • Single

  • multiple

  • multi-level

  • hierarchical

  • hybrid

What are the types of inheritance in Java?
SMMHH

8
New cards

No, multiple inheritance is not supported in Java.

Is multiple inheritance supported in Java? Yes or No

9
New cards
  • extends

  • one

What is single inheritance?

A type of inheritance where a class _______ only ___ other class.

<p>What is single inheritance?</p><p>A type of inheritance where a class _______ only ___ other class.</p>
10
New cards
  • 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():

}

}

<p>A cat (subclass) inherits from an animal (superclass).<br><br><span style="color: yellow;">class message_super </span>{</p><p>Public void display() {</p><p>System.out.println("l am from superclass");</p><p>}</p><p>}</p><p><span style="color: rgb(255, 127, 0);">class message_sub e____ds message_super</span> {</p><p>public static void main(String args[]) {</p><p>M____<span style="color: rgb(29, 231, 245);"><strong>__</strong></span>s__ m_____ = new message_sub()</p><p>Message.display():</p><p>}</p><p>}</p>
11
New cards
  • Multi level inheritance

  • extends

  • extends another

Type of inheritance, When a class _______ another class, which in turn e______ a___ class.

<p>Type of inheritance, When a class _______ another class, which in turn e______ a___ class.</p>
12
New cards
<p></p>

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()

}

}

13
New cards

hierarchical inheritance

A type of inheritance, When one superclass is inherited by multiple subclasses.

<p>A type of inheritance, When one superclass is inherited by multiple subclasses.</p>
14
New cards

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

}

15
New cards

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_________

<p>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_________</p>
16
New cards

No, a final method cannot be overridden.

Can a final method be overridden? yes or no

17
New cards
  • 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(); 

}

}

18
New cards

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.