1. Origin of Java

Q: Who developed the Java programming language?

  • A) Dennis Ritchie
  • B) James Gosling
  • C) Guido van Rossum
  • D) Bjarne Stroustrup

Answer: B


2. Features of Java

Q: Which of the following is NOT a feature of Java?

  • A) Platform independence
  • B) Garbage collection
  • C) Low-level memory manipulation
  • D) Object-oriented

Answer: C


3. Java Elements

Q: Which of the following is a valid identifier in Java?

  • A) 1variable
  • B) @variable
  • C) variable1
  • D) int

Answer: C


4. Primitive Data Types

Q: Which data type is used to store true or false values in Java?

  • A) int
  • B) char
  • C) boolean
  • D) float

Answer: C


5. Control Statements - if-else

Q: What will be the output of the following code?

int num = 10;
if (num > 5) {
    System.out.println("Greater");
} else {
    System.out.println("Smaller");
}
  • A) Smaller
  • B) Greater
  • C) Compiler Error
  • D) None of the above

Answer: B


6. Conditional Operator

Q: What does the following expression return: (x > 10) ? x : 10;

  • A) 10 if x is greater than 10
  • B) The value of x if x is less than or equal to 10
  • C) 10 if x is less than or equal to 10
  • D) None of the above

Answer: C


7. Switch Statement

Q: Which of the following is valid in a Java switch statement?

  • A) long
  • B) float
  • C) String
  • D) double

Answer: C


8. Loops

Q: Which loop guarantees at least one iteration in Java?

  • A) for
  • B) while
  • C) do-while
  • D) None of the above

Answer: C


9. Break Statement

Q: What is the effect of the break statement inside a loop?

  • A) Skips the current iteration
  • B) Exits the loop
  • C) Terminates the program
  • D) Continues to the next statement

Answer: B


10. Classes and Objects

Q: Which of the following is a valid way to create an object of the class MyClass?

class MyClass {
    int x;
}
  • A) MyClass obj = new MyClass();
  • B) MyClass obj;
  • C) MyClass();
  • D) new MyClass;

Answer: A


11. Constructors

Q: Which of the following is true about constructors in Java?

  • A) They have a return type
  • B) They must have the same name as the class
  • C) They are called explicitly by the programmer
  • D) They cannot be overloaded

Answer: B


12. Method Overloading

Q: What differentiates method overloading in Java?

  • A) Different names for methods
  • B) Same name but different return types
  • C) Same name, different number or types of parameters
  • D) None of the above

Answer: C


13. this Variable

Q: What does the this keyword refer to in Java?

  • A) The parent class
  • B) The current object
  • C) The next object
  • D) The class itself

Answer: B


14. Abstract Classes

Q: Which of the following is true about abstract classes in Java?

  • A) They can be instantiated
  • B) They cannot have concrete methods
  • C) They must contain abstract methods
  • D) They can contain both abstract and concrete methods

Answer: D


15. Static Class Members

Q: Which statement about static class members is true?

  • A) They belong to the instance of the class
  • B) They cannot be accessed without creating an instance
  • C) They belong to the class, not instances
  • D) They can only be accessed in the same package

Answer: C



Comments

Popular posts from this blog

Java MCQ