303). Which of this keyword can be used in a subclass to call the constructor of superclass?
[A]super
[B]this
[C]extent
[D]extends
Show Answer
Correct Answer: super
Notes:
Answer: a
Explanation: None.
304). What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
[A]Method overloading
[B]Method overriding
[C]Method hiding
[D]None of the mentioned
Show Answer
Correct Answer: Method overriding
Notes:
Answer: b
Explanation: None.
305). Which of these keywords can be used to prevent Method overriding?
[A]static
[B]constant
[C]protected
[D]final
Show Answer
Correct Answer: final
Notes:
Answer: d
Explanation: To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden.
306). Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
[A]super(void);
[B]superclass.();
[C]super.A();
[D] super();
Show Answer
Correct Answer: super();
Notes:
Answer: d
Explanation: None.
307). At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”
public interface Status
{
/* insert qualifier here */ int MY_VALUE = 10;
}
[A]final, native, private
[B]final, static, protected
[C] final, private, abstract
[D] final, static, public
Show Answer
Correct Answer: final, static, public
Notes:
Answer: d
Explanation: Every interface variable is implicitly public static and final.
308). Which of these is supported by method overriding in Java?
public interface Status
{
/* insert qualifier here */ int MY_VALUE = 10;
}
[A]Abstraction
[B]Encapsulation
[C]Polymorphism
[D]None of the mentioned
Show Answer
Correct Answer: Polymorphism
Notes:
Answer: c
Explanation: None.
309). What will be the output of the following Java program?
class Alligator
{
public static void main(String[] args)
{
int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
int [][]y = x;
System.out.println(y[2][1]);
}
}
[A]2
[B]3
[C]7
[D] Compilation Error
Show Answer
Correct Answer: 7
Notes:
Answer: c
Explanation: Both x,and y are pointing to the same array.
310). What will be the output of the following Java program?
final class A
{
int i;
}
class B extends A
{
int j;
System.out.println(j + " " + i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
[A]2 2
[B]3 3
[C]Runtime Error
[D]Compilation Error
Show Answer
Correct Answer: Compilation Error
Notes:
Answer: d
Explanation: class A has been declared final hence it cannot be inherited by any other class. Hence class B does not have member i, giving compilation error.
output:
$ javac inheritance.java
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
i cannot be resolved or is not a field
311). What will be the output of the following Java program?
class Abc
{
public static void main(String[]args)
{
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0]: null;
}
}
[A]Compilation error
[B]An exception is thrown at run time
[C]The variable first is set to null
[D]The variable first is set to elements[0]
Show Answer
Correct Answer: The variable first is set to elements[0]
Notes:
Answer: d
Explanation: The value at the 0th position will be assigned to the variable first.
312). What will be the output of the following Java program?
class A
{
int i;
public void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
public void display()
{
System.out.println(j);
}
}
class Dynamic_dispatch
{
public static void main(String args[])
{
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
r.display();
}
}
Show Answer
Correct Answer: 2
Notes:
Answer: b
Explanation: r is reference of type A, the program assigns a reference of object obj2 to r and uses that reference to call function display() of class B.
output:
$ javac Dynamic_dispatch.java
$ java Dynamic_dispatch
2