In Java, which of the following statements is/are True? S1: The ‘final’ keyword applied to a class definition prevents the class from being extended through derivation. S2: A class can only inherit one class but can implement multiple interfaces. S3: Java permits a class to replace the implementation of a method that it has inherited. It is called method overloading.
S1 and S2 only
Let's analyze each statement regarding Java programming concepts like the final keyword, inheritance, interfaces, and method overriding vs. overloading.
The question asks us to determine the truthfulness of three statements about Java. We will examine each statement individually.
Statement S1 says: The ‘final’ keyword applied to a class definition prevents the class from being extended through derivation.
Based on the definition of the final keyword applied to a class in Java, Statement S1 is True.
Statement S2 says: A class can only inherit one class but can implement multiple interfaces.
Based on Java's rules for inheritance and interface implementation, Statement S2 is True.
Statement S3 says: Java permits a class to replace the implementation of a method that it has inherited. It is called method overloading.
Since Statement S3 incorrectly identifies method overriding as method overloading, Statement S3 is False.
Let's summarize our findings:
We are looking for the option that reflects S1 and S2 are true, and S3 is false.
| Statement | Truth Value | Explanation |
|---|---|---|
| S1: Final keyword on class prevents extension | True | A final class cannot be inherited. |
| S2: Single class inheritance, multiple interface implementation | True | Java classes support single inheritance and can implement any number of interfaces. |
| S3: Replacing inherited method is overloading | False | Replacing an inherited method's implementation is called method overriding, not overloading. |
Based on this analysis, only statements S1 and S2 are true.
Comparing our findings with the given options:
Therefore, the correct option is the one stating that S1 and S2 are true only.
| Concept | Description | Keyword |
|---|---|---|
| Final Class | A class declared with the final keyword. Cannot be subclassed. | final |
| Inheritance | Mechanism where one class acquires the properties (fields and methods) of another class. Single inheritance for classes in Java. | extends |
| Interface | A blueprint of a class. It has static constants and abstract methods. A class can implement multiple interfaces. | interface, implements |
| Method Overriding | Providing a specific implementation of a method that is already defined in the parent class, within the subclass. Same method signature. | Inheritance, Polymorphism |
| Method Overloading | Defining multiple methods in the same class with the same name but different parameter lists. | Polymorphism |
Java supports several types of inheritance through classes and interfaces:
While multiple inheritance of implementation is not allowed for classes, multiple inheritance of type is achieved through implementing multiple interfaces.
Both interfaces and abstract classes are used to achieve abstraction and polymorphism in Java, but they have key differences:
Interfaces define a contract for what a class must do, while abstract classes provide a common base for related classes, potentially including some shared behavior.
It's crucial to distinguish between method overriding and method overloading:
Overriding occurs at runtime (runtime polymorphism), while overloading is resolved at compile time (compile-time polymorphism).
When an applet begins, which of the following sequence methods is CORRECT?
1) start()
2) paint()
3) init()
What will be the output of the following Java program?
class test
{public static void main (String args [ ])
{
System.out.println(20 + 30 + "Java");
System.out.println("Java" + 20 + 30);
}
}
In Java, the 'PreparedStatement' interface is a sub interface which is used to execute __________ query.
Which of the following is NOT a java primitive type?
Which of the following is/are the rules to declare variables in Java?