OOP Pillars Flashcards

1
Q

__________ in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object

A

Inheritance

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

The idea behind inheritance in Java is that you can create new classes that are built upon existing _______.

A

classes

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

When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also.

True or False

A

True

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

___________ means “many forms”, and it occurs when we have many classes that are related to each other by inheritance.

A

Polymorphism

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

___________ lets us inherit attributes and methods from another class. ___________ uses those methods to perform different tasks.

A

Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks.

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

Inheritance represents the ___ relationship which is also known as a ___________ relationship.

A

Inheritance represents the IS-A relationship which is also known as a parent-child relationship.

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

What are the Advantages of Inheritance?

A
  • For Method Overriding (so runtime polymorphism can be achieved).
  • For Code Reusability.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

____ is a group of objects which have common properties. It is a template or blueprint from which objects are created.

A

class

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

________ is a class which inherits the other class. It is also called a derived class, extended class, or child class.

A

subclass

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

__________ is the class from where a subclass inherits the features. It is also called a base class or a _____ ____.

A

Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.

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

________ is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.

A

reusability

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

The _______ keyword indicates that you are making a new class that derives from an existing class. The meaning of “_______” is to increase the functionality.

class Subclass-name extends Superclass-name

{

//methods and fields added here

}

A

extends

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

What are the three types of inheritance in java?

A

single, multilevel and hierarchical

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

In java programming, ________ and ______ inheritince is supported through interface only.

A

In java programming, multiple and hybrid inheritance is supported through interface only.

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

Is multiple inheritance supported by Java?

A

No

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

The most common use of ___________ in OOP occurs when a parent class reference is used to refer to a child class object.

A

polymorphism

17
Q

Any Java object that can pass more than one IS-A test is considered to be __________

A

polymorphic

18
Q

If a class has multiple methods having same name but different in parameters, it is known as ______ _________

A

Method Overloading

19
Q

If we have to perform only one operation, having same name of the methods _________ the ___________ of the program.

A

If we have to perform only one operation, having same name of the methods increases the readability of the program.

20
Q

What are the two ways to overload the method in java?

A
  • By changing number of arguments
  • By changing the data type

class Adder{

static int add(int a, int b){return a+b;} // 2 arguments

static int add(int a, int b, int c){return a+b+c;} //3 arguments

}

21
Q

Method overloading is not possible by changing the return type of the method.

True or False

A

True

22
Q

If subclass (child class) has the same method as declared in the parent class, it is known as _____ ________ in Java

A

method overriding

23
Q

______ overriding is used to provide the specific implementation of a method which is already provided by its superclass.

A

  • Method overriding is used to provide the specific implementation of a method which is already provided by its superclass.
24
Q

_______ overriding is used for runtime polymorphism

A

Method overriding is used for runtime polymorphism

25
Q

What are the 3 rules required for method overriding to work?

A
  • The method must have the same name as in the parent class
  • The method must have the same parameter as in the parent class.
  • There must be an IS-A relationship (inheritance).
26
Q

Can a static method be overridden?

A

No, a static method cannot be overridden.

27
Q

____________ in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit.

A

Encapsulation

28
Q

In __________, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class.

A

encapsulation

29
Q

We can create a fully encapsulated class in Java by making all the data members of the class _______.

A

private

30
Q

Once the data member of class have been made private we can use _____ and _____ methods to ___ and ___ data

A

Once the data member of class have been made private we can use getter and setter methods to get and set data

31
Q

The ____ ____ class is the example of a fully encapsulated class.

A

Java Bean

32
Q

What are the 4 access modifiers?

A
  • private
  • default
  • protected
  • public
33
Q

What is the accessibility scope of each access modifier?

private

default

protected

public

A
34
Q

__________ is a process of hiding the implementation details and showing only functionality to the user.

A

Abstraction

example: sending SMS where you type the text and send the message. You don’t know the internal processing about the message delivery.

Within Parent class

public abstract int calculateSalary();

Child Class

You define what calculateSalary() function does in the child class

35
Q

________ lets you focus on what the object does instead of how it does it.

A

Abstraction

36
Q

______________ is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods.

A

Generalization

IE. taking two similar classes that have shared attributes, and then creating a superclass and moving the shared attributes into and then extend those attributes to the subclasses. So the two original classes are now subclasses of the superclass that now contains the once shared characterson

37
Q

___________ means creating new subclasses from an existing class. If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.

A

Specialization

ie. When it comes to Specialization, if there is a property that is only applicable to a specific subclass, such as Degree of Hazardousness, that property is placed in the class Piece of Cargo where-in this class also has all the properties of the Freight class with the concept of Generalization.

38
Q

Any Java object that can pass more than one ____ test is considered to be polymorphic.

A

IS-A