Java Programs Questions and Answers
100% Pass
What is the main method signature required to run a Java program?
✔✔ public static void main(String[] args)
What keyword is used to define a class in Java?
✔✔ class
How do you display text in the console in Java?
✔✔ System.out.println()
What file extension must a Java source file have?
✔✔ .java
What command compiles a Java program?
✔✔ javac
1
,What command runs a compiled Java program?
✔✔ java
What is the default access modifier for a class in Java if none is specified?
✔✔ package-private
Which function is the entry point of a Java application?
✔✔ main()
What is the purpose of comments in Java?
✔✔ To explain code without affecting execution
What is the correct syntax for a single-line comment in Java?
✔✔ // This is a comment
What is the correct syntax for a multi-line comment in Java?
✔✔ /* This is a comment */
2
, Which keyword is used to create an object in Java?
✔✔ new
What is the default value of an uninitialized int variable in Java?
✔✔ 0
How do you declare a constant variable in Java?
✔✔ final
Which function is used to get user input in Java?
✔✔ Scanner.next()
What is the keyword used to define a method in Java?
✔✔ void (or a specific return type)
Which class is used to read input from the console?
✔✔ Scanner
3