313). Which of these class is superclass of every class in Java?
[A]String class
[B]Object class
[C] Abstract class
[D]ArrayList class
Show Answer
Correct Answer: Object class
Notes:
Answer: b
Explanation: Object class is superclass of every class in Java.
314). Which of these method of Object class can clone an object?
[A]Objectcopy()
[B]copy()
[C]Object clone()
[D]clone()
Show Answer
Correct Answer: Object clone()
Notes:
Answer: c
Explanation: None.
315). Which of these method of Object class is used to obtain class of an object at run time?
[A]get()
[B]void getclass()
[C]Class getclass()
[D]None of the mentioned
Show Answer
Correct Answer: Class getclass()
Notes:
Answer: c
Explanation: None.
316). Which of these keywords can be used to prevent inheritance of a class?
[A]super
[B]constant
[C]class
[D]final
Show Answer
Correct Answer: final
Notes:
Answer: d
Explanation: Declaring a class final implicitly declared all of its methods final, and makes the class inheritable.
317). Which of these keywords cannot be used for a class which has been declared final?
[A]abstract
[B]extends
[C]abstract and extends
[D]none of the mentioned
Show Answer
Correct Answer: abstract
Notes:
Answer: a
Explanation: A abstract class is incomplete by itself and relies upon its subclasses to provide a complete implementation. If we declare a class final then no class can inherit that class, an abstract class needs its subclasses hence both final and abstract cannot be used for a same class.
318). Which of these class relies upon its subclasses for complete implementation of its methods?
[A]Object class
[B]abstract class
[C]ArrayList class
[D] None of the mentioned
Show Answer
Correct Answer: abstract class
Notes:
Answer: b
Explanation: None.
319). What will be the output of the following Java program?
abstract class A
{
int i;
abstract void display();
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class Abstract_demo
{
public static void main(String args[])
{
B obj = new B();
obj.j=2;
obj.display();
}
}
[A]0
[B]2
[C]Runtime Error
[D]Compilation Error
Show Answer
Correct Answer: 2
Notes:
Answer: b
Explanation: class A is an abstract class, it contains a abstract function display(), the full implementation of display() method is given in its subclass B, Both the display functions are the same. Prototype of display() is defined in class A and its implementation is given in class B.
output:$ javac Abstract_demo.java
$ java Abstract_demo
2
320). What will be the output of the following Java program?
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
A obj2 = new A();
System.out.print(obj1.equals(obj2));
}
}
[A]false
[B]true
[C]1
[D]Compilation Error
Show Answer
Correct Answer: false
Notes:
Answer: a
Explanation: obj1 and obj2 are two different objects. equals() is a method of Object class, Since Object class is superclass of every class it is available to every object.
output:
$ javac Output.java
$ java Output
false
321). What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
Object obj = new Object();
System.out.print(obj.getclass());
}
}
[A]Object
[B]class Object
[C]class java.lang.Object
[D]Compilation Error
Show Answer
Correct Answer: class java.lang.Object
Notes:
Answer: c
Explanation: None.
output:
$ javac Output.java
$ java Output
class java.lang.Object
322). What will be the output of the following Java code?
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}
[A]true
[B]false
[C]String associated with obj1
[D]Compilation Error
Show Answer
Correct Answer: String associated with obj1
Notes:
Answer: c
Explanation: toString() is method of class Object, since it is superclass of every class, every object has this method. toString() returns the string associated with the calling object.
output:
$ javac Output.java
$ java Output
A@1cd2e5f