1. Which of the keywords can be used in a subclass to call the constructor of a superclass?
A) super
B) it
C) extent
d) extends
Answer: A
Explanation: None.
2. What is the process of defining a method in a subclass with a signature of the same name and type as a method in a superclass?
a) method overloading
B) method overriding
C) hide method
d) none of the mentioned
Answer: B
Explanation: None.
3. Which of these keywords can be used to prevent method overriding?
A) fixed
B) stable
C) protected
d) Final
Answer: D
Explanation: To prevent a method from being overridden, specify the last as a modifier at the start of its declaration. Last declared methods cannot be overridden.
4. Which of the following is a sub-constructor that has no parameters, subclass B has no criteria of superclass A?
A) super (zero);
B) superclass; ();
C) super. ();
D) super ();
Answer: D
Explanation: None.
5. On line number 2 in the following code, choose 3 valid data-type properties / properties among "last, static, basic, public, private, abstract, protected".
Public interface status
{
/ * Insert qualifier here * / int MY_VALUE = 10;
}
A) last, native, private
B) final, stable, protected
C) final, personal, abstract
D) final, stable, public
Answer: D
Explanation: Each interface variable is explicitly public static and final.
6. Which of the following is supported by the overriding method in Java?
A) abstraction
b) Encapsulation
C) polymorphism
d) none of the mentioned
Answer: C
Explanation: None.
7. What will be the output of the following Java program?
Square crocodile
{
public static void main (String [] args)
{
int [] x [] = {{1,2}, {3,7,5}, {4, x,}, 4}};
int [] [] y = x;
Println (y [2] [1]);
}
}
a) 2
b) 3
C) 7
D) compilation error
Answer: C
Explanation: Both x and y point to the same array.
8. What will be the output of the following Java program?
Last class a
{
int i;
}
Class B extends A
{
Int j;
System.out.println (j + "" + i);
}
Class heritage
{
public static void main (String [] args[]
{
B obj = new B ();
obj.display ();
}
}
a) 2 2
b) 3 3
c) runtime error
D) compilation error
Answer: D
Explanation: Class A is declared final so it cannot be inherited by any other class. Therefore Class B does not have member i, giving a compilation error.
Output: $ javac inheritance.java thread exception "main" java.lang.Error: unreserved compilation problem: I cannot resolve or not have a field
9. What will be the output of the following Java program?
Class abc
{
public static void main (String [] args)
{
String [] element = {"for", "tea", "too"};
String first = (Elements. Learning> 0)? Elements [0]: null;
}
}
A) compilation error
B) An exception is thrown at run time
C) the variable is first set to zero
D) Variable is set to first elements [0]
Answer: D
Explanation: The value at location 0 will be assigned to the first variable.
10. Which class of the word should be used?
A) super
B) it
C) extent
d) extends
Answer: D
Explanation: None.
11. A class member declared as protected becomes a member of which type of subclass?
A) public member
b) Private member
C) Protected Members
d) stable member
Answer: B
Explanation: A class member declared protected becomes a private member of a subclass.
12. Which of the following is the correct way of inheriting Class A by Class B?
a) class B + class A {}
B) class B class A {} inherited
C) Extension of class B {{
D) class B expands class A {}
Answer: C
Explanation: None.