Java Features and Basics MCQs: 12 Solved Questions with Explanations

Test your Java foundation with 12 solved MCQs, then trace the rules behind compilation, naming, classes, packages and two small programs.

KnowledgeGate Team

Exam prep & CS education

Updated 16 Nov 20267 min read
Java Features and Basics MCQs: 12 Solved Questions with Explanations

Introductory Java MCQs mix language features, compiler commands, naming rules, object basics and tiny execution traces. You may know the definition and still lose the option because of one word such as static, final, javac or args[2]. Answer each one first, verify the decisive rule, and run the two small code traces by hand. Use Coding & Skill Development Courses when you want the wider catalog route after this focused drill.

Java basics MCQs: use one four-step check

For every question, follow the same check:

  1. Identify whether it tests source syntax, compile-time behaviour, runtime behaviour or a style convention.

  2. Underline the exact word that changes the answer.

  3. Substitute a concrete value or command.

  4. Reject every remaining option with one rule.

Keep one baseline in mind. Save public class HelloJava in HelloJava.java, with System.out.println("Java ready"); inside main. Compile it using javac HelloJava.java, confirm that HelloJava.class is produced, then run java HelloJava. The output is Java ready. Here javac compiles Java source into bytecode. The JVM executes that bytecode using its runtime machinery, which may interpret instructions and JIT-compile frequently executed code.

Java compilation and features: Questions 1 to 3

Question 1

Which of the following statements is true?

  • A. The JAVA compiler produces a code for JVM, which is executed by a JAVA interpreter.

  • B. The JAVA compiler produces a code directly for JAVA interpreter.

  • C. The JAVA compiler directly executes code in JVM.

  • D. The JAVA compiler helps in directly executing a code on different operating systems.

Correct answer: A. javac HelloJava.java produces bytecode in HelloJava.class, which the JVM executes. A modern JVM may interpret and JIT-compile bytecode, so A's durable idea is that the compiler produces code for the JVM. B omits that target, C wrongly gives execution to the compiler, and D ignores the compatible JVM required on each operating system.

Question 2

Which command is used to convert the code written in Java to bytecode?

  • A. javap

  • B. java

  • C. javadoc

  • D. javac

Correct answer: D. javac HelloJava.java compiles the source and produces HelloJava.class. java HelloJava launches the program, javap HelloJava disassembles a class file, and javadoc HelloJava.java generates documentation.

Question 3

Which of the following is the most important feature that makes Java suitable for Internet applications?

  • A. Faster execution

  • B. Object oriented & robust

  • C. Portable and distributed

  • D. Simple & secure

Correct answer: C. Portable bytecode can run through compatible JVM implementations on different platforms, while Java's networking libraries support distributed programs. Robustness and security are also Java features, but C directly combines the two Internet-application concerns tested here. Java is not always faster than native code.

Pipeline diagram showing HelloJava.java compiled to HelloJava.class, run by a JVM, producing “Java ready” on Windows, Linux, and macOS.

Java keywords, access and naming: Questions 4 to 6

Question 4

Which of the following is NOT a valid Java keyword?

  • A. goto

  • B. interface

  • C. volatile

  • D. include

Correct answer: D. interface and volatile are Java keywords. goto is reserved even though Java has no goto statement, while include is not a keyword. Java can use import java.util.Scanner;, unlike C's #include, but import does not paste source text into a file.

Question 5

Which of the following is NOT an access modifier in Java ?

  • A. public

  • B. private

  • C. protected

  • D. accessible

Correct answer: D. public, private and protected are explicit access modifiers; accessible is neither a Java keyword nor a modifier. A member declared as int score = 12; has package-private access. Package-private is the access level created by omitting a modifier, not a fourth modifier keyword.

Question 6

Which of the following statements related to Java is FALSE?

  • A. All class names should start with an upper-case letter.

  • B. It is not mandatory for the name of the program file to exactly match the class name.

  • C. All method names should start with a lower-case letter.

  • D. Java is a case-sensitive language.

Correct answer: B. public class HelloJava must be saved as HelloJava.java, including case, so B is false as an unconditional statement. UpperCamelCase for classes and lowerCamelCase for methods are conventions, matching the word "should" in A and C. Java is case-sensitive, so score and Score are distinct; a file with no public top-level type has more naming freedom.

Java naming and access chart comparing matching class filenames, case-sensitive variables, three access modifiers, package-private access, and invalid accessible.

Java classes and core library basics: Questions 7 to 9

Question 7

Which of the following statements is/are true regarding JAVA?
A. Constants that cannot be changed are declared using the “Static” keyword.
B. A class can inherit only one class, but it can implement multiple interfaces.

  • A. A is true

  • B. B is true

  • C. Both (A) and (B) are true

  • D. Neither (A) nor (B) is true

Correct answer: B. Test the statements separately. final int maxAttempts = 3; cannot be reassigned, while static int attempts = 0; belongs to the class but may change, so A is false. class Quiz extends Activity implements Scorable, Resettable extends one class and implements two interfaces, so B is true. static final remains a common combination for a class-level constant.

Question 8

What happens if a Java class has no constructors defined?

  • A. The compiler throws an error

  • B. The compiler adds a default constructor automatically

  • C. A parameterized constructor is added by default

  • D. The object cannot be created using new keyword

  • E. Only static methods can be accessed

Correct answer: B. With class Counter { int value; }, the compiler supplies a no-argument default constructor, so new Counter() works and the int field starts at its default value 0. If the author declares Counter(int start), the compiler no longer supplies Counter() automatically.

For the broader relationship between classes, inheritance and interfaces, continue with Object Oriented Technology Explained.

Question 9

'System' is a class in which of the following packages of Java programming language?

  • A. Java.util

  • B. Java.sql

  • C. Java.io

  • D. Java.lang

Correct answer: D. Option D uses Java.lang, but Java package names are case-sensitive and the correct spelling is java.lang; it is imported implicitly. By contrast, familiar types include java.util.Scanner, java.sql.Connection and java.io.File. Its System.out member appears in the next question.

Reading Java execution traces: Questions 10 to 12

Question 10

In the statement ‘System.out.println("Hello World!")’, the keyword ‘out’ stands for the following:

  • A. Static member of the ‘System’ class

  • B. An interface in the Java standard library

  • C. A method in the ‘System’ class

  • D. Class in the Java standard library

Correct answer: A. System is the java.lang.System class, out is its public static field referring to a PrintStream, and println("Hello World!") is the invoked method. Although the stem calls out a keyword, it is technically a field name, not a Java keyword.

Question 11

What is the output of the following code?

java
public class Demo {
    public static void main(String[] args) {
        int x = 5;
        System.out.println(++x * 2);
    }
}
  • A. 12

  • B. 11

  • C. 10

  • D. Compile time error

Correct answer: A. x starts at 5. Prefix ++x changes it to 6 before multiplication, so 6 * 2 = 12, and println prints 12. With x++ * 2, Java would use 5 first and print 10, then x would become 6.

Question 12

What output is produced by java cmd a b c d when this code runs?

java
class cmd {
    public static void main(String args[]) {
        System.out.println(args[2]);
    }
}
  • A. c

  • B. cmd

  • C. b

  • D. a

Correct answer: A. The arguments map as args[0] = "a", args[1] = "b", args[2] = "c" and args[3] = "d". Java arrays are zero-indexed. The launcher class name cmd is not stored in args, so System.out.println(args[2]); prints c.

Two-panel Java runtime trace showing x changing from 5 to 6, producing 12, and args[2] containing “c” in the command-line array.

One Java program that joins the tested rules

Put the rules together in one compilable file:

java
public class HelloJava {
    static int runs = 1;
    final int maxAttempts = 3;

    public static void main(String[] args) {
        int x = 5;
        System.out.println("Java ready");
        System.out.println(++x * 2);
        System.out.println(args[2]);
    }
}

Compile with javac HelloJava.java, then run java HelloJava a b c d. The three output lines are:

Code
Java ready
12
c

The public class matches HelloJava.java. runs is class-level because it is static; maxAttempts cannot be reassigned after initialization because it is final. System comes from java.lang, and out is static. Prefix increment changes 5 to 6, so the multiplication gives 12. The third command-line argument, args[2], is c.

Next, use String Handling in Java: Pool, Immutability, Interview Qs to study the String[] args type and wider Java String behaviour.

Java basics revision plan and next step

Recall the chain: .java -> javac -> .class -> JVM; final means no reassignment; static marks a class member; public class HelloJava belongs in HelloJava.java; System.out is a class plus static field; ++x increments before use; args[2] is the third argument.

If you scored 10 to 12, rerun only each missed rule. At 7 to 9, compile the worked program and repeat all 12 questions. At 0 to 6, rebuild the foundation with the Complete Java Course before retrying. For structured concepts plus MCQs and coding questions, continue with the Java Course: Concepts, MCQs & Coding Questions.