Top 500+ Advanced Java Interview Questions 2020-2021 - 3

Question: 11

What do you understand by private, protected and public?

These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive.

There is no real difference between protected and the default type within the context of the same package; however the protected keyword allows visibility to a derived class in a different package.

Question: 12

What is a compilation unit?

A compilation unit is a Java source code file.

Question: 13

How are this() and super() used with constructor?

this() is used to invoks a constructor of the same class, super() is used to invoke a super class’s constructor.

Question: 14

What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and its name. We do not initialize it.

But defining means declaration + initialization.

E.g. String s; is just a declarations while String s = new String (“abcd”); or String s = “abcd”; are both definitions.

Question: 15

Is a class a sub class of itself?

A class is a subclass of itself.

Related Questions