Java Quiz 1
Which of the following is not a primitive data type in Java?
A) int
B) boolean
C) String
D) char
A) int
B) boolean
C) String
D) char
C) String
What is the output of System.out.println(10/3); in Java?
A) 3.33
B) 3
C) 3.0
D) 4
A) 3.33
B) 3
C) 3.0
D) 4
B) 3
Which method is used to find the length of a string in Java?
A) size()
B) length()
C) getLength()
D) len()
A) size()
B) length()
C) getLength()
D) len()
B) length()
What does the static keyword mean in Java?
A) The method or variable can be accessed without creating an instance of the class.
B) The method or variable is only accessible within the class it is defined.
C) The method or variable is inherited by all subclasses.
D) The method or variable is immutable.
A) The method or variable can be accessed without creating an instance of the class.
B) The method or variable is only accessible within the class it is defined.
C) The method or variable is inherited by all subclasses.
D) The method or variable is immutable.
A) The method or variable can be accessed without creating an instance of the class.
What is the default value of a boolean variable in Java if it’s not explicitly initialized?
A) true
B) false
C) null
D) Not initialized
A) true
B) false
C) null
D) Not initialized
B) false
Which of the following is the correct way to declare an array in Java?
A) int arr[] = new int[5];
B) int arr = new int[5];
C) arr[] = new int[5];
D) int arr[5];
A) int arr[] = new int[5];
B) int arr = new int[5];
C) arr[] = new int[5];
D) int arr[5];
A) int arr[] = new int[5];
What is the return type of the hashCode() method in Java?
A) int
B) float
C) String
D) long
A) int
B) float
C) String
D) long
A) int
Which of the following is used to terminate a switch statement in Java?
A) break
B) exit
C) return
D) stop
A) break
B) exit
C) return
D) stop
A) break
What is the purpose of the super keyword in Java?
A) It is used to call the parent class constructor.
B) It is used to call the parent class method.
C) It is used to access the parent class fields.
D) All of the above.
A) It is used to call the parent class constructor.
B) It is used to call the parent class method.
C) It is used to access the parent class fields.
D) All of the above.
All of the above.
Which keyword is used to create an abstract class in Java?
A) abstract
B) static
C) final
D) virtual
A) abstract
B) static
C) final
D) virtual
A) abstract
What is the size of an int in Java?
A) 8 bits
B) 16 bits
C) 32 bits
D) 64 bits
A) 8 bits
B) 16 bits
C) 32 bits
D) 64 bits
32 bits
Which of the following is true about a final class in Java?
A) It can be extended.
B) It cannot be extended.
C) It cannot extend other classes.
A) It can be extended.
B) It cannot be extended.
C) It cannot extend other classes.
B) It cannot be extended.
Which method must be implemented by all threads in Java?
A) start()
B) run()
C) stop()
D) execute()
A) start()
B) run()
C) stop()
D) execute()
B) run()
What is the default value of a static variable of type int?
A) 0
B) null
C) Not assigned
D) Compiles with an error
A) 0
B) null
C) Not assigned
D) Compiles with an error
A) 0
Which keyword is used to prevent method overriding in Java?
A) final
B) static
C) abstract
D) private
A) final
B) static
C) abstract
D) private
A) final
How can you access the first element of an array named arr?
A) arr[1]
B) arr[0]
C) arr.first()
D) arr.get(0)
A) arr[1]
B) arr[0]
C) arr.first()
D) arr.get(0)
B) arr[0]
Which of these is used to make an object of a class serializable in Java?
A) Serializable interface
B) Serialize interface
C) Serialized interface
D) ObjectOutput interface
A) Serializable interface
B) Serialize interface
C) Serialized interface
D) ObjectOutput interface
A) Serializable interface
Which operator is used for instance comparison in Java?
A) ==
B) ===
C) instanceof
D) equals()
A) ==
B) ===
C) instanceof
D) equals()
C) instanceof
What will this code print? System.out.println(‘\u0031’);
A) 1
B) Error
C) Special character
D) None of the above
A) 1
B) Error
C) Special character
D) None of the above
A) 1
Which of the following is a type of polymorphism in Java?
A) Compile time polymorphism
B) Execution time polymorphism
C) Multiple polymorphism
D) Multilevel polymorphism
A) Compile time polymorphism
B) Execution time polymorphism
C) Multiple polymorphism
D) Multilevel polymorphism
A) Compile time polymorphism
Which component of Java is responsible for running the compiled Java bytecode?
A) JDK
B) JRE
C) JVM
D) JIT
A) JDK
B) JRE
C) JVM
D) JIT
C) JVM
What is the purpose of the PATH environment variable in Java?
To locate the Java compiler