Java Data Types
Which of the following is a valid primitive data type in Java?
- int
- integer
- Int
- doublet
- duble
Object-Oriented Concepts
Which keyword is used to inherit a class in Java?
- extends
- inherit
- implements
- expands
- extnd
Writing Methods
What is the correct way to declare a method that returns an integer value in Java?
- public int calculate()
- public void calculate()
- int calculate void()
- calculate int()
- public Integer calculate void()
Java Collections
Which collection type automatically prevents duplicate elements in Java?
- Set
- List
- ArrayList
- Map
- AraySet
Exception Handling
Which keyword is used to handle exceptions in Java?
- catch
- tryy
- excep
- handle
- cacth
Access Modifiers
Which access modifier allows a class member to be accessed only within the same package and subclass?
- protected
- private
- default
- public
- protectd
Java Loops
Which loop is best to use in Java when the number of iterations is known in advance?
- for
- while
- do-while
- foreach
- fro
Interfaces vs Abstract Classes
Which Java feature allows a class to provide implementations for multiple behaviors but not store variables?
- Interface
- Abstract class
- Class
- Struct
- Inerface
Java String Comparison
Which method should be used to compare two String values for content equality in Java?
- equals
- ==
- compareTo
- equalto
- equalsIgnoreCase
Java Method Overloading
What is method overloading in Java?
- Defining multiple methods with the same name but different parameters
- Calling a method from its superclass
- Writing the same method in two different classes
- Implementing a method from an interface
- Creating a method with different return types only