Declarations , Modifiers , Interfaces, OOPs , Constructors Flashcards

1
Q

Class And Interface

A

A class can implement any number of classes.
A class can extend only one class at a time.
An interface can extend any number of interfaces.

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

Methods in interface

A

Every method present in interface is by default public. Hence at the time of overriding/implementing that method, compulsory we should declare that method as public. We will get compile time errors otherwise.

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

Abstract class methods

A

For abstract class methods, if we don’t want to provide implementation, then compulsory we should declare that method as abstract, otherwise we will get compile time error.

We cannot declare abstract method with final, private, and static modifiers.

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

If a class implements an interface

A

If a class implements an interface, then compulsory we should provide implementation for every abstract method, otherwise we have to declare class as abstract. Every interface method is public and hence at the time of implementation we should declare as public only.

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

Main objective of default methods in interfaces

A

We can extend functionality of interface by adding new methods without effecting implementation classes.

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

Overriding method resolution

A

In overriding method resolution is always based on runtime object. Hence child class method will be executed.

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

Interfaces and abstract classes

A

Every variable present inside interface is always public, static and final and we cannot declare instance variables.

But abstract class can contain instance variables.

Both interface and abstract class can contain abstract methods.

Both interface and abstract class can contain static methods.

Constructors concept applicable only for classes but not for interfaces.

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

When will a default constructor be generated?

A

If we are not writing any constructor then only default constructor will be executed.

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

Declaring methods with default keyword

A

We can declare methods with default keyword only in interface but not in class. Hence we will get compile time error.

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

Variable resolution

A

Variable resolution is always based on reference type but not based on runtime object. We used Parent reference and hence we got the parent value.

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