- APolymorphism
- BInheritance
- CEncapsulation
- DAbstraction
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
Inheritance
In most programming languages, a method can return only one value at a time. Therefore, the correct answer is (a) 1. When you define a method and specify a return type, you are indicating the type of value that the method will return. The method can perform computations, process data, and then provide a single result of the specified type.
For example, in Java, a method declaration might look like this:
public int add(int a, int b) { return a + b; }
In this example, the add method takes two integer parameters (a and b) and returns a single integer result, which is the sum of a and b. The method specifies int as the return type, indicating that it will return an integer value.
If a method needs to return multiple values, one common approach is to use other data structures like arrays, objects, or collections to bundle and return multiple values within a single container.
The correct answer is:
(c) 2220
Explanation:
int a = Integer.parseInt(P); - Converts the string "20" to an integer and assigns it to variable a.int b = Integer.valueOf(Q); - Converts the string "22" to an integer and assigns it to variable b.System.out.println(a + "" + b); - Concatenates the values of a and b as strings and prints the result. In this case, it prints "20" + "22", resulting in "2022".
In Java, the extends keyword is used to indicate that one class is inheriting the properties and methods of another class. For example, public class SubClass extends SuperClass shows that SubClass inherits from SuperClass. Inheritance allows a class to use methods and fields from another class, promoting code reuse and logical hierarchies in object-oriented programming. This structure facilitates polymorphism and method overriding, which are essential features of Java's object-oriented paradigm. The implements keyword, on the other hand, is used when a class wants to implement an interface. super is used to refer to the immediate superclass, and this refers to the current instance of the class.
In Java, Object is the superclass of all other classes. Every class in Java, either directly or indirectly, inherits from the Object class. This means that methods defined in the Object class, such as toString(), hashCode(), and equals(), are available to all Java classes. This inheritance forms the root of Java's class hierarchy, providing fundamental behavior that all Java objects share. Understanding this concept is crucial for utilizing polymorphism and implementing custom behavior in subclasses.
In Java, the super keyword is used to refer to the immediate parent class. When used in a constructor, super() calls the constructor of the parent class. This is essential when the superclass has a parameterized constructor or when you want to ensure that the parent class's initialization logic runs before the subclass's logic. The super keyword can also be used to access methods and variables of the parent class that might be overridden in the subclass.