Revature prep OOP Flashcards

1
Q

What is OOP

A

Object Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance.

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

What is an Object

A

An Object is an entity that has state and behavior, it can be defined as an instance of a class. Objects contain addresses and take up some space in memory. Objects can communicate without knowing the details of each others data or the code. The only necessary thing is the type of message accepted and the type of response returned by the objects.

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

What is a Class

A

Classes are templates or blueprints that are used to create objects and to define object data types and methods. They do not consume space.

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

Advantages of OOP vs Procedure oriented programming

A

OOP makes development and maintenance easier whereas POP is not easy to manage if the code grows as project size increases.
OOP provides data hiding whereas POP the global data can be accessed from anywhere.

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

What is a Constructor

A

A constructor is a block of code similar to the method. It is called when an instance of the object is created, and memory is allocated for the object. It is a special type of method which is used to initialize the object.

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

When is a constructor called

A

When an object is created, compiler makes sure that constructors for all of its sub objects are called. if members have default constructors or constructors without parameters then these constructors are called automatically, otherwise parameterized constructors can be called using initializer list.

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

Why is it called constructor

A

It is called constructor because it constructs the values at the time of the object creation. It is not necessary to write a constructor for a class. It is because compilers create a default constructor if your class doesn’t have any.

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

What are the 3 rules for constructors

A
  1. The constructor name must be the same as the class name.
  2. The constructor must have no explicit return type.
  3. A Java constructor cannot be abstract, static, final and synchronized.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the 2 types of constructors

A

Default and Parameterized.

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

What is a default constructor

A

The default constructor is a no-args constructor that Java compiler inserts on your behalf, it contains a default call to super, which is the default behavior. If you implement any constructor then you no longer receive a default constructor.

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

What is a parameterized constructor

A

A constructor which has a specific number of parameters. The parameterized constructor is used to provide different values to the distinct objects. However, you can provide the same values also.

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

What is constructor overloading

A

constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types.

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

Constructor vs Method

A

Constructor: used to initialize the state of an object, must not have a return type, invoked implicitly, provides default constructor if none in class, name needs to be same as class name.

Method: used to expose the behavior of an object, must have a return type, invoked explicitly, not provided by the compiler, can be same or different name from class name.

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

What are the OOP pillars

A

Inheritance, Polymorphism, Encapsulation and Abstraction

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

What is inheritance

A

Inheritance is a mechanism in which one object acquires all the properties and behaviors of a parent object. 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