OOP Questions Flashcards

1
Q

What are the advantages of OOPS concepts?

A
Simplicity: OOPS programming objects model real world objects, so the complexity is reduced and the program structure is clear.
Modularity: Each object forms a separate entity whose internal workings are decoupled from other parts of the system.
Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.
Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
Maintainability: Objects can be maintained separately, making locating and fixing problems easier.
Reusability: Objects can be reused in different programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between Procedural programming and OOPS?

A

Procedural language is based on functions but object oriented language is based on real world objects.
Procedural language gives importance on the sequence of function execution but object oriented language gives importance on states and behaviors of the objects.
Procedural language exposes the data to the entire program but object oriented language encapsulates the data.
Procedural language follows top down programming paradigm but object oriented language follows bottom up programming paradigm.
Procedural language is complex in nature so it is difficult to modify, extend and maintain but object oriented language is less complex in nature so it is easier to modify, extend and maintain.
Procedural language provides less scope of code reuse but object oriented language provides more scope of code reuse.

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

What are the core concepts of OOPS?

A
Abstraction
Encapsulation
Polymorphism
Inheritance
Composition
Association
Aggregation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Abstraction?

A

Abstraction is an OOPS concept to construct the structure of the real world objects. During this construction only the general states and behaviors are taken and more specific states and behaviors are left aside for the implementers.

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

What is Encapsulation?

A

Encapsulation is an OOPS concept to create and define the permissions and restrictions of an object and its member variables and methods. A very simple example to explain the concept is to make the member variables of a class private and providing public getter and setter methods. Java provides four types of access level modifiers: public, protected, no modifier and private.

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

What is the difference between Abstraction and Encapsulation?

A
“Program to interfaces, not implementations” is the principle for Abstraction and “Encapsulate what varies” is the OO principle for Encapsulation.
Abstraction provides a general structure of a class and leaves the details for the implementers. Encapsulation is to create and define the permissions and restrictions of an object and its member variables and methods.
Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using four types of access level modifiers: public, protected, no modifier and private.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Polymorphism?

A

Polymorphism is the occurrence of something in various forms. Java supports various forms of polymorphism like polymorphic reference variables, polymorphic method, polymorphic return types and polymorphic argument types.

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

What is Inheritance?

A

A subclass can inherit the states and behaviors of it’s super class is known as inheritance.

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

What is multiple inheritance?

A

A child class inheriting states and behaviors from multiple parent classes is known as multiple inheritance.

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

Why Java does not support multiple inheritance?

A

Java was designed to be a simple language and multiple inheritance introduces complexities like diamond problem. Inheriting states or behaviors from two different type of classes is a case which in reality very rare and it can be achieved easily through an object association.

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

What is the meaning of “IS-A” and “HAS-A” relationship?

A

“IS-A” relationship implies inheritance. A sub class object is said to have “IS-A” relationship with the super class or interface. If class A extends B then A “IS-A” B. It is transitive, that is, if class A extends B and class B extends C then A “IS-A” C. The “instanceof” operator in java determines the “IS-A” relationship.

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

What is an Object?

A

Object is instance of class.

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

What is a Class?

A

A class is the specification or template of an object.

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