- APolymorphism
- BInheritance
- CEncapsulation
- DAbstraction
Inheritance
The given program segment is a finite loop. The loop will iterate as long as the condition i != 0
is true. The loop variable i
starts at 5, and it decreases by 2 in each iteration (i -= 2
). The loop will continue until i
becomes 0 or less, at which point the condition becomes false, and the loop exits.
So, the correct answer is:
(a) finite
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, 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.