Object Oriented Programming Flashcards

1
Q

Constructor vs. Method Facts:

Constructor

A
  1. A constructor is used to initialize the state of an object.
  2. A constructor must not have a return type.
  3. the constructor is invoked implicitly.
  4. The Java compiler provides a default constructor if you don’t have any constructor in a class.
  5. the constructor name must be the same as the class name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe object-oriented programming?

A

A methodology or paradigm to design a program using classes and objects.

It includes concepts such as: Object, Classes, Inheritance, Polymorphism, Abstraction, Encapsulation

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

One of the 4 pillar of OOP is Encapsulation. What is Encapsulation ?

A

Encapsulation is a process of wrapping code and data together into a single unit

We can encapsulate an entire class by making all the data members of the class private (data hiding). We can use the getter and setter methods.

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

What is a parameterized Constructor ?

A

A parameterized constructor is one that has a specific number of parameters. It’s used to provide different values to the distinct objects.

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

What is Constructor Overloading ?

A

Constructor overloading is when there are more than one constructor with different parameter lists. Each constructor performs a different task. They are differentiated by the number of parameters in the list and their list types.

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

What is the default constructor ?

A

The default constructor is a no-args constructor that the Java compiler inserts automatically. It contains a default call to super()

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

What is method overloading ?

A

Method overloading is when a class has multiple methods of the same name, but different in parameters.

A method can be overloaded by :

  1. changing number of arguments
  2. changing the data type

This is a compile time polymorphism

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

What is an abstract method ?

A

A method that is declared as abstract and does not have implementation

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

What are some advantages of inheritance ?

A
  1. Method Overriding

2. Code Reusability

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

What is the extends keyword ?

A

The extends keyword indicates that you are making a new class that derives from an existing class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

Constructor vs. Method Facts:

Method

A
  1. A method is used to expose the behavior of an object.
  2. A method must have a return type.
  3. The method is invoked explicitly.
  4. The method is not provided by the compiler in any case.
  5. The method name may or may not be the same as class name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When is a constructor called ?

A

A constructor is called when an object is created.

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

What is generalization (abstraction)

A

Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass.

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

What is an object?

A

Any entity that has state and behavior. It can be defined as an instance of a class.

Ex. chair, pen, table, keyboard

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

What is method overriding ?

A

Method overriding is when a subclass has the same method as declared in the parent class

  1. Used to provided the specific implementation of a method which is already provided by its superclass.
  2. A static method cannot be overridden.
  3. Runtime polymorphism
17
Q

What are some advantages of OOP over Procedural Oriented Programming?

A
  1. OOP makes development and maintenance easier as project size increases.
  2. OOP provides data hiding
18
Q

What is a constructor ?

A

A constructor is called when an instance of the object is created, and memory is allocated for the object. Used to initialize the object

19
Q

What are the 3 types of inheritance in java ?

A

single, multilevel, and hierarchical

20
Q

What is an abstract class ?

A

An abstract class is one that is declared as abstract. It needs to be extended and its method implemented. It cannot be instantiated.

21
Q

One of the four pillars of OOP is Inheritance. Describe Inheritance.

A

Inheritance is a mechanism in which one object acquires all of the properties and behaviors of a parent object.

The idea behind it is that you can create new classes that are built upon existing classes. When inheriting, you can reuse methods and fields of the parent class and also add new ones.

It represents the IS-A relationship which is known as a parent-child relationship

22
Q

What is Sub Class/Child Class ?

A

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

23
Q

What are the 2 ways to achieve abstraction ?

A
  1. Abstract class

2. Interface

24
Q

One of the 4 pillars of OOP is Abstraction. Define Abstraction.

A

Abstraction is a process of hiding the implementation details and showing only functionality to the user. It focuses on what the object does and not how it does it.

25
Q

What is Specialization ?

A

Specialization means creating new subclasses from an existing class. It certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.

26
Q

What is a class?

A

A class is a “blueprint from which individual objects are created”. It’s a template that is used to create objects, and to define object data types and methods that may be used by the object.

27
Q

What is a Super class/Parent class

A

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

28
Q

One of the four pillars of OOP is Polymorphism. Describe Polymorphism

A

Polymorphism is the ability of an object to take on many forms. It allows us to perform a single action in many ways.

It occurs when a parent class reference is used to refer to a child class object.