inheritance Flashcards

1
Q

Inheritance 1

A

Inheritance is the process by which the new child subclass automatically.
You need to use the keywords “extends” in order to use inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Inheritance 2

A

There are two classes involved to do inheritance.
One is called the parent class. Also called super class
one is called the child class. Also called the base class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inheritance demo

A

Here Childclass is extending the parentclass.
everytime there is an inheritance, the child class can inherit these methods from the parent class.
It only works one way not the oher way around

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Single inheritance

A

Java supports single inheritance, by which a class may inherit from only one direct parent class.
By design, Java doesn’t support
multiple inheritance in the language because studies have shown that multiple inheritance
can lead to complex, often difficult-to-maintain code.

but you can do a work around by implementing multiple interfaces.

Java also supports multiple levels of inheritance, by which one class may extend
another class, which in turn extends another class. You can extend a class any number of
times, allowing each descendent to gain access to its ancestor’s members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Show DEMO

A

multiple level of inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Abstraction

A

an abstract class may include nonabstract methods and variables
In fact, an abstract class is not required to
include any abstract methods.
you make abstract method with with keyword abstract.
you can only make abstract mthod inside an abstract class.
If a subclass fails to override the method, an error will result. Abstract methods are used to
ensure that a subclass implements the method.
Like inheritance, you should extend an abstract class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Abstract method

A

Abstract methods and abstract classes are defined with the abstract key word.
* Abstract methods have no body, and their header must end with a semicolon.
* An abstract method must be overridden in a subclass.
* When a class contains an abstract method, it cannot be instantiated. It must serve as
a superclass.
* An abstract class cannot be instantiated. It must serve as a superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

interfaces

A

Although Java doesn’t allow multiple inheritance, it does allow classes to implement any
number of interfaces. An interface is an abstract data type that defi nes a list of abstract
public methods that any class implementing the interface must provide.
You implement interfaces using the keyword implements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

overriding

A

Sometimes a subclass inherits a method from its superclass, but the method is inadequate
for the subclass’s purpose. Because the subclass is more specialized than the superclass, it is
sometimes necessary for the subclass to replace inadequate superclass methods with more
suitable ones. This is known as method overriding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly