WorksheetsS4_Java Basics Quiz
Total questions: 20
Worksheet time: 10mins
What is the purpose of using objects as parameters in methods?
To enforce data encapsulation
To reduce memory usage
To allow methods to modify the original object
To increase the method's execution speed
What does 'Call by Value' mean in Java?
Passing the reference of the variable
Passing a copy of the variable's value
Passing the variable itself
Passing the variable's address
Which keyword is used to declare a constant in Java?
static
immutable
final
const
What is method overloading?
Defining multiple methods with the same name but different parameters
Creating a method that calls itself
Changing the return type of a method
Using a method from a parent class
What is the main concept of inheritance in Java?
Preventing method overriding
Combining multiple classes into one
Hiding data from other classes
Creating new classes from existing classes
What is the purpose of the 'super' keyword in Java?
To call a method from the current class
To access a method from the parent class
To create a new instance of a class
To define a constant value
What is encapsulation in object-oriented programming?
Creating multiple instances of a class
Inheriting properties from a parent class
Overriding methods in subclasses
Hiding the internal state of an object
What does the 'this' keyword refer to in Java?
A local variable
The parent class
The current object instance
A static method
What is polymorphism in Java?
The ability to hide data within a class
The ability to inherit properties from multiple classes
The ability to create multiple classes
The ability to call the same method on different objects
What does the 'static' keyword indicate in Java?
It is used to define an abstract class
It is a method that cannot be overridden
It can only be accessed within the same class
It belongs to the class rather than instances of the class
What is the purpose of the 'final' keyword when applied to a method?
To prevent the method from being overridden
To define a method that can be inherited
To indicate that the method is abstract
To allow the method to be static
What is the role of the 'abstract' keyword in Java?
To define a method that cannot be instantiated
To indicate that a method must be implemented in a subclass
To create a class that cannot be subclassed
To allow multiple inheritance
What is the significance of the 'interface' keyword in Java?
To define a class that cannot be instantiated
To define a class with static methods only
To allow for method overloading
To create a contract that implementing classes must follow
What does the 'volatile' keyword indicate in Java?
That a variable is static
That a variable is only accessible within the same class
That a variable is immutable
That a variable can be accessed by multiple threads
What is the purpose of the 'protected' access modifier in Java?
To allow access to subclasses and classes in the same package
To allow access from any class
To allow access only within the same package
To restrict access to the class itself
What is the difference between '== 'and 'equals()' in Java?
There is no difference; they are interchangeable
'==' is used for primitive types, while 'equals()' is used for objects
'==' compares object references, while 'equals()' compares object values
'==' is faster than 'equals()'
What is the purpose of the 'instanceof' operator in Java?
To compare two objects
To cast an object to a specific type
To create a new instance of a class
To check if an object is an instance of a specific class or interface
What is the purpose of the 'abstract' class in Java?
To prevent inheritance from the class
To provide a base for other classes to extend
To define a class with only static methods
To create instances of the class
What is the role of the 'throws' keyword in Java?
To declare that a method can throw exceptions
To define a method that cannot throw exceptions
To create a new exception type
To catch exceptions in a method
What is the purpose of the 'default' keyword in an interface in Java?
To define a method that must be implemented by all implementing classes
To provide a default implementation of a method in an interface
To indicate that a method is static
To prevent method overriding in subclasses
