static, final and the main Method Questions
45 min · Beginner
static ties a member to the class instead of an object, final stops something from changing, and public static void main(String[] args) is the doorway the JVM uses to start your program. These three topics produce a steady stream of definition questions and initialization-order puzzles.
Topics in this lesson
- Recap: static members and static blocks
- final in three places, and final vs finally vs finalize
- Why main is public static void
- Predict the output: initialization order
- Traps: static with this, final with a mutable object
Interview questions this lesson answers
- What does
staticmean in Java? - What is a static block?
- What does
finalmean for a variable, a method and a class? - What is the difference between final, finally and finalize?
- Why is main
public static void? - What is
String[] argsin main? - Can the main method be overloaded?
- Can main be declared
final,synchronizedor withString... args? - What happens if main is not static?
- Can we run a program without a main method?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.