Inheritance and Polymorphism Flashcards

1
Q

class reusability has two forms …. and ….

A

composition and inheritance

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

composition is called a ….

A

has- a

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

has - a or composition means

A

placing a reference / object of a class in another class

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

inheritance is (is-a)

A

extending a class with another class

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

inheritance means

A

that a new class inherits from an existing class, it inherits all its members and characteristics

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

subclass constructor has to call… directly or indirectly

A

base/parent class

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

base/ parent class is called using

A

super()

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

super can be the last statement in the constructor of subclass (yes / no)

A

no, it must be the first statement in the subclass

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

why does super class constructor must be called

A

to make sure all class members are initialized

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

access modifier for an overriding method has to be the same ?

A

no it can be more but not less ( more access is given )

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

if an access modifier protected then the child class can be ?

A

public or none

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

any method defined in java is overridable by default unless it is ….

A

final

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

method of subclass has the same signature of super class?

A

true

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

method signture is

A

same name, same parameters and return type

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

overloading is between methods

A

between methods of the same class

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

same method name but different number of parameters or parameter type but not return type is considered overloading

A

true

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

a class can have how many parent classes?

A

exactly one

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

abstracted can not be …. or…..

A

inherited or instantiated

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

a method declared abstract has no …

A

body

20
Q

abstract has to be

A

overridden

21
Q

abstract class can contain … classes

A

both concrete (non-abstract) and abstract

22
Q

constructors and static methods cant be declared abstract ? why?

A

yes , because they cant be inherited

we should call super for them to get invoked

23
Q

can an abstract class have a constructor ?

A

yes

24
Q

what happens if we try calling an abstract class constructor ?

A

compilation error

25
Q

if there at least one abstract method the class

A

the class must be abstract

26
Q

an abstract can be instantiated with a reference to any of its subclasses which is called an

A
upcasting 
parent name = new sub()
27
Q

polymorphism is

A

using methods to perform different tasks this allows us to perform a single action in different ways

28
Q

forms of polymorphism

A

overloading and overriding

29
Q

why polymorphism?

A

allows us to perform a single action in different ways

write general methods in super and implements them later in detail in subclasses

30
Q

dynamic binding

A

is making a thing change or overloaded

31
Q

dynamic binding happens in

A

runtime

32
Q

in dynamic binding the reference of an object is used? t or f

A

false

33
Q

dynamic binding speed is

A

low

34
Q

example for dynamic binding is

A

method overriding

35
Q

static binding happens in

A

compile time

36
Q

in static binding the … of an object is used

A

reference

37
Q

speed of static binding is

A

high

38
Q

static binding example is

A

overloading

39
Q

upcasting is

A

converting an object of a subclass to its superclass done implicitly (indirectly)

40
Q

downcasting is

A

converting an object of a superclass to one of its subclasses must be explicitly (directly)

41
Q

Upcasting example

A
Person p;
Employee emp = new Employee();
p = emp;
42
Q

DownCasting example

A

Person p = new Employee();
Employee emp;
emp = (Employee) p;

43
Q

instanceOf operator can be used to …

A

to check whether an object is a certain class type or not

44
Q

can you assign a superclass variable to superclass?

A

true

45
Q

can you assign a subclass variable to subclass object?

A

true

46
Q

can you assign superclass variable to a subclass object ?

A

true

47
Q

can you assign a subclass variable superclass object?

A

nope, must be done via explicit casting