-
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.
-
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)
-
Which of the following is not a valid Java data type?
A) float
B) char
C) string
D) doubleAnswer: C) string
-
What does OOP stand for in Java?
A) Object-Oriented Programming
B) Operational Output Processing
C) Open Operating Platform
D) Ordered Object ProgrammingAnswer: A) Object-Oriented Programming
-
Which keyword is used to define a class in Java?
A) class
B) type
C) struct
D) objectAnswer: A) class
-
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();
-
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.
-
Which of the following is used to implement inheritance in Java?
A) extends keyword
B) implements keyword
C) inherits keyword
D) extends classAnswer: A) extends keyword
-
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 errorAnswer: B) 2
-
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 aboveAnswer: D) All of the above
Comments