Create New Post

Java MCQs - 1

  1. Which of the following is true about Java?
    A) Java is a low-level programming language.
    B) Java is a purely procedural language.
    C) Java is platform-independent.
    D) Java is primarily used for system-level programming.

    Answer: C) Java is platform-independent.

  2. What is the correct syntax for the main method in Java?
    A) public void main(String[] args)
    B) public static int main(String[] args)
    C) public static void main(String[] args)
    D) static void main(String[] args)

    Answer: C) public static void main(String[] args)

  3. Which of the following is not a valid Java data type?
    A) float
    B) char
    C) string
    D) double

    Answer: C) string

  4. What does OOP stand for in Java?
    A) Object-Oriented Programming
    B) Operational Output Processing
    C) Open Operating Platform
    D) Ordered Object Programming

    Answer: A) Object-Oriented Programming

  5. Which keyword is used to define a class in Java?
    A) class
    B) type
    C) struct
    D) object

    Answer: A) class

  6. What is the correct way to create an object of a class in Java?
    A) MyClass.new();
    B) new MyClass();
    C) create MyClass();
    D) object MyClass;

    Answer: B) new MyClass();

  7. What is the purpose of the 'static' keyword in Java?
    A) It specifies that a method or variable belongs to the class, not the instance.
    B) It indicates that a method or variable can only be accessed from within the same package.
    C) It restricts the access of a method or variable to the same class only.
    D) It specifies that a method or variable is constant and cannot be changed.

    Answer: A) It specifies that a method or variable belongs to the class, not the instance.

  8. Which of the following is used to implement inheritance in Java?
    A) extends keyword
    B) implements keyword
    C) inherits keyword
    D) extends class

    Answer: A) extends keyword

  9. What is the output of the following code?

    int x = 5; int y = 2; System.out.println(x / y); 

    A) 2.5
    B) 2
    C) 2.0
    D) 2.5 with a runtime error

    Answer: B) 2

  10. What is the purpose of the 'final' keyword in Java?
    A) It indicates that a class cannot be extended.
    B) It specifies that a method cannot be overridden.
    C) It denotes that a variable's value cannot be changed.
    D) All of the above

    Answer: D) All of the above

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

84199