Programming - Programming in Java
MCQS
A. A scripting language
B. A markup language
C. A programming language
D. A database language
Java is a programming language.
A. constant
B. const
C. final
D. static
'final' is used to declare constants in Java.
A. main() method
B. start() method
C. execute() method
D. run() method
The 'main()' method is the entry point in Java.
A. int
B. float
C. double
D. class
'class' is not a primitive data type in Java.
A. Refer to the current object
B. Refer to the parent class
C. Refer to the child class
D. Refer to the global scope
'this' refers to the current object in Java.
A. new
B. malloc
C. instantiate
D. create
'new' is used for object instantiation in Java.
A. true
B. false
C. 0
D. 1
The default value of a boolean variable is 'false'.
A. Using interfaces
B. Using abstract classes
C. Using multiple extends keyword
D. Java doesn't support multiple inheritance
Multiple inheritance is achieved using interfaces in Java.
A. Invoke superclass constructor
B. Refer to the subclass object
C. Invoke a static method
D. Create a superclass instance
'super' is used to invoke the superclass constructor.
A. ArrayList
B. HashSet
C. HashMap
D. Vector
'Vector' is a synchronized collection class in Java.
A. Define exceptions
B. Throw exceptions
C. Catch exceptions
D. Propagate exceptions
'throws' is used to propagate exceptions in Java.
A. finalize()
B. dispose()
C. clean()
D. destroy()
'finalize()' is called during garbage collection.
A. Hello3
B. Hello12
C. Hello21
D. Compile error
Concatenation from left to right: "Hello" + 1 = "Hello1", then "Hello1" + 2 = "Hello21".
A. final
B. static
C. private
D. protected
'final' prevents method overriding in Java.
A. Check if an object is an instance of a class
B. Compare two objects
C. Check if a class is an instance of an object
D. Check if an object is null
'instanceof' is used to check if an object is an instance of a class.
A. Abstract class can have constructors
B. Interface can have constructors
C. Abstract class can have abstract methods
D. Interface can have non-abstract methods
Abstract classes can have constructors, while interfaces cannot.
A. Skip to the next iteration
B. Exit the loop
C. Restart the loop
D. Skip to the next loop
'break' is used to exit a loop in Java.
A. int[] arr;
B. int arr();
C. array arr;
D. array[] arr;
'int[] arr;' declares an array of integers in Java.
A. using
B. extends
C. implements
D. inheritance
'implements' is used to implement interfaces in Java.
A. 7
B. 8
C. 7.8
D. 8.0
'Math.floor(7.8)' returns the largest integer less than or equal to 7.8, which is 7.0.
A. Define exceptions
B. Throw exceptions
C. Catch and handle exceptions
D. Propagate exceptions
'try-catch' is used to catch and handle exceptions in Java.
A. Runnable
B. Serializable
C. Comparable
D. Cloneable
'Serializable' is a marker interface in Java.
A. Using the run() method
B. Extending the Thread class
C. Implementing the Runnable interface
D. Both B and C
Both extending Thread and implementing Runnable can create a thread in Java.
A. Define exceptions
B. Throw exceptions
C. Catch exceptions
D. Cleanup code
'finally' is used for cleanup code that always executes, whether an exception occurs or not.
A. Create a static method
B. Create a static variable
C. Define a constant
D. Create a static class
'static' is used to create static variables in Java.
A. compare()
B. equals()
C. compareTo()
D. equality()
'equals()' is used to compare objects for equality in Java.
A. 3.33
B. 3.0
C. 3
D. 3.333333
Division involving a double results in a double, so 10 / 3.0 is 3.333333.
A. Object obj = new Object();
B. class obj = new class();
C. Object obj = createObject();
D. obj = createObject();
'new' is used to create an object of a class in Java.
A. Execute the default case
B. Define a default value
C. Provide a default constructor
D. Specify default permissions
'default' is used for the default case in a switch statement.
A. true
B. false
C. Compile error
D. Runtime error
String literals with the same content are interned, so "Java" == "Java" is true.
A. read()
B. input()
C. System.in.read()
D. Scanner.next()
'Scanner.next()' is commonly used to read data from the keyboard in Java.
A. Garbage collection
B. Exception handling
C. Object cloning
D. Method overloading
'finalize' is called during garbage collection in Java.
A. const int CONSTANT = 5;
B. final int CONSTANT = 5;
C. static final int CONSTANT = 5;
D. public final int CONSTANT = 5;
'static final' is used to declare constants in an interface in Java.
A. ArrayList arr = new ArrayList();
B. List arr = new List();
C. List arr = new ArrayList();
D. ArrayList arr = new List();
'ArrayList arr = new ArrayList();' creates an ArrayList in Java.
A. Invoke the superclass constructor
B. Refer to the parent class
C. Invoke the subclass constructor
D. Create a superclass instance
'super()' is used to invoke the superclass constructor in Java.