OOP Basic Flashcards

1
Q

Inner Class

A

also nested class, group class together to be more readable and maintainable (can be private or protected)

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

Sub Class

A

Class that inherits from another class

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

Static methods

A

method directly accessible without instantiating an object

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

Static variable

A

variable directly accessible without instantiating an object

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

4 Principles of OOP

A

Encapsulation
Polymorphism
Abstraction
Inheritance

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

Example/Definition of Encapsulation

A

Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.

Levels are Public, Protected, Private, Internal, and Protected Internal.

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

Overriding

A

allow subclass or child class to provide specific implementation (same signature)

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

Overloading

A

same method name different signature

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

Abstract Class

A

class declared abstract, may or may not include abstract methods. Cannot be instantiated but can be inherited

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

Interface

A

completely abstract class used to group related methods with empty bodies. It is a concept of OOPs that allows you to declare methods without defining them.

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

Interface vs Abstract Class

A

Abstract Class

  • Can have both abstract and non abstract method
  • Can be private, public,
  • Can provide the implementation of an interface

Interface

  • Only Abstract methods
  • public by default
  • cannot provide implementation of an abstract class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Specifiers

A

Public - Visible to all classes
Protected - Visible to clases with in the package and subclasses of other package
Default - Visible to the classes within the package
Private - Visible within the class. Not accessible outside the class

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

Example/Definition Polymorphism

A

Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

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

Example/Definition Inheritance

A

Inheritance is a concept where one class shares the structure and behavior defined in another class. If Inheritance applied to one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

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

Example/Definition of Abstraction

A

Abstraction is a useful feature of OOPS, and it shows only the necessary details to the client of an object. Meaning, it shows only required details for an object, not the inner constructors, of an object. Example – When you want to switch on the television, it is not necessary to know the inner circuitry/mechanism needed to switch on the TV. Whatever is required to switch on TV will be shown by using an abstract class.

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

Advantage of OOP

A
  • OOPs allows clarity in programming thereby allowing simplicity in solving complex problems
  • Code can be reused through inheritance thereby reducing redundancy
  • Data and code are bound together by encapsulation
  • OOPs allows data hiding, therefore, private data is kept confidential
  • Problems can be divided into different parts making it simple to solve
  • The concept of polymorphism gives flexibility to the program by allowing the entities to have multiple forms
17
Q

What is an Object

A

An object is a real-world entity which is the basic unit of OOPs for example chair, cat, dog, etc.

18
Q

What is a Class

A

An extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods)

19
Q

What are the limitations of inheritance?

A
  • Increases the time and effort required to execute a program as it requires jumping back and forth between different classes
  • The parent class and the child class get tightly coupled
  • Any modifications to the program would require changes both in the parent as well as the child class
  • Needs careful implementation else would lead to incorrect results
20
Q

Limitation of OOP

A
  • Usually not suitable for small problems
  • Requires intensive testing
  • Takes more time to solve the problem
  • Requires proper planning
  • The programmer should think of solving a problem in terms of objects
21
Q

Association

A

is a relationship between two separate classes and the association can be of any type say one to one, one to may etc. It joins two entirely separate entities.

22
Q

Aggregation

A

specialized form of association. Child object can exist without parent (E.g. Wallet can have Money but doesnt need money)

23
Q

Composition

A

specialized form of aggregation. Child Object cannot exist without Parent (e.g. House and Room, you need a house to have a room)

24
Q

Covariant Return Type

A

Specifies that the return type may vary in the subclass

25
Q

Compile Time Polymorphism

A

Overloading a static method, where polymorphism is done during compile

26
Q

Runtime Polymorphism

A

A call to an overridden method is resolved at runtime. The program will determine the method to be called base on the object being referred to.

27
Q

Upcasting

A

The reference variable of Parent class refers to the object of Child class

28
Q

Downcasting

A

Casting a parent object to a child object, must be explicit.