Prev Next

Java / Access Modifiers

1. Can a class be declared as private?

Posted on Apr 1, 2016 by Senthil Kumar.

A class cannot be declared private.

Read full answer

2. Can a class be declared protected?

Posted on Apr 1, 2016 by Senthil Kumar.

No. A class cannot be protected.

Read full answer

3. Can an interface be declared protected?

Posted on Apr 1, 2016 by Senthil Kumar.

No. An interface cannot be protected.

Read full answer

4. What are the applicable access specifier for a class/interface/abstract class?

It can be public or no access specified(default access).

Read full answer

5. Can we run a Java program without main method?

No. However until Java 7, we can execute by using static blocks. Prior to Java 7, the Jvm loads the class, execute static block before finding main method and invoke it. During this process, any code in the static block got executed. // will not work in Java 7 and above. public class Test { stati...

Read full answer

«
»

Comments & Discussions