Inheritance and Polymorphism Flashcards

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/31

flashcard set

Earn XP

Description and Tags

Flashcards for reviewing Inheritance and Polymorphism concepts in Java.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

32 Terms

1
New cards

Inheritance

The process by which one object acquires the properties of another object, supporting hierarchical classification.

2
New cards

Code Reusability (Inheritance)

The code written in the Superclass is common to all subclasses, allowing child classes to directly use the parent class code.

3
New cards

Method Overriding (Inheritance)

Achievable only through Inheritance, it is one of the ways by which Java achieves Run Time Polymorphism.

4
New cards

Abstraction (Inheritance)

The concept of abstract where we do not have to provide all details is achieved through inheritance, showing only functionality to the user.

5
New cards

extends keyword

Used to inherit a class, incorporating the definition of one class into another.

6
New cards

Single Inheritance

A single subclass extends from a single superclass.

7
New cards

Multilevel Inheritance

A subclass extends from a superclass, and then the same subclass acts as a superclass for another class.

8
New cards

Hierarchical Inheritance

Multiple subclasses extend from a single superclass.

9
New cards

Multiple Inheritance

A single subclass extends from multiple superclasses. Note that Java doesn't directly support this.

10
New cards

Hybrid Inheritance

A combination of two or more types of inheritance (e.g., hierarchical and multiple inheritance).

11
New cards

Polymorphism

A feature that allows one interface to be used for a general class of actions, with the specific action determined by the exact nature of the situation.

12
New cards

Method Overloading

Occurs when there is more than one method of the same name in the class, with different parameters.

13
New cards

Method Overriding

In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass.

14
New cards

Compile-Time Polymorphism (Static Polymorphism)

The call to the method is resolved at compile-time, achieved through Method Overloading.

15
New cards

Runtime Polymorphism (Dynamic Polymorphism)

The call to an overridden method is resolved dynamically at runtime rather than at compile-time, achieved via Method Overriding.

16
New cards

super keyword

Used to differentiate the members of superclass from the members of subclass if they have the same names, or to invoke the superclass constructor from subclass.

17
New cards

Packages

Containers for classes that are used to keep the class name space compartmentalized.

18
New cards

What is Inheritance in Object-Oriented Programming?

Inheritance is the mechanism by which one class inherits the properties and behavior (methods) of another class, facilitating hierarchical classification.

19
New cards

What does the extends keyword do in Java?

The extends keyword is used to create a subclass from a superclass, allowing the subclass to inherit its methods and properties.

20
New cards

What is the main difference between Method Overloading and Method Overriding?

Method Overloading occurs when multiple methods with the same name exist in the same class but with different parameters, whereas Method Overriding involves redefining a method from a superclass in a subclass.

21
New cards

What is the concept of Polymorphism?

Polymorphism allows methods to do different things based on the object it is acting upon, enabling one interface to represent different underlying forms (data types).

22
New cards

What is the primary purpose of Packages in Java?

Packages group related classes and interfaces together, helping to avoid naming conflicts and making it

23
New cards

What is an Abstract Class in Java?

An abstract class is a class that cannot be instantiated and may contain abstract methods (without implementations) as well as concrete methods (with implementations).

24
New cards

What is the purpose of an Abstract Class?

The purpose of an abstract class is to provide a base for subclasses to extend, allowing them to inherit and implement abstract methods.

25
New cards

Can an Abstract Class have Concrete Methods?

Yes, an abstract class can have concrete methods that can be used or overridden by subclasses.

26
New cards

What happens if a Subclass does not implement all Abstract Methods?

If a subclass does not implement all abstract methods of its abstract superclass, the subclass itself must also be declared as abstract.

27
New cards

How is an Abstract Class defined in Java?

An abstract class is defined using the keyword 'abstract' in its class declaration, e.g., 'abstract class ClassName { … }

28
New cards

What is the difference between an Abstract Class and an Interface?

An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods (until Java 8 introduced default methods). An abstract class allows for the definition of instance variables, whereas interfaces cannot.

29
New cards

Can an Abstract Class extend another Abstract Class?

Yes, an abstract class can inherit from another abstract class, allowing it to implement or extend the functionality defined in the parent abstract class.

30
New cards

Is it possible to create properties in an Abstract Class?

Yes, an abstract class can contain properties (fields) to store data, which can be used by its subclasses.

31
New cards

What is the significance of Abstract Classes in Java?

Abstract classes help in establishing a basic structure for derived classes, promoting code reusability and a clear hierarchy for class design.

32
New cards

How many Abstract Methods can an Abstract Class have?

An abstract class can have any number of abstract methods, including none; it can be a fully abstract class or a mix of abstract and concrete methods.