Java / Access Modifiers
1.
Can a class be declared as private?
2.
Can a class be declared protected?
3.
Can an interface be declared protected?
4.
What are the applicable access specifier for a class/interface/abstract class?
5.
Can we run a Java program without main method?
Could not find what you were looking for? send
us the question and we would be happy to answer your question.
1. Can a class be declared as private?
Posted
on Apr 1, 2016 by
Senthil Kumar.
A class cannot be declared private.
2. Can a class be declared protected?
Posted
on Apr 1, 2016 by
Senthil Kumar.
No. A class cannot be protected.
3. Can an interface be declared protected?
Posted
on Apr 1, 2016 by
Senthil Kumar.
No. An interface cannot be protected.
4. What are the applicable access specifier for a class/interface/abstract class?
It can be public or no access specified(default access).
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 { static { System.out.println("Static block executed."); } }