1.Which of these class is superclass of every class in Java?
a) String class
b) Object class
c) Object interface
d) Collections
Answer: Object class in jva.lang package is the super class of all classes in Java Technology.
2.What are the methods that are declared as protected access in Object class?
a.toString() and Equals()
b.clone() and finalize()
c.hashCode() and Equals()
d.notify() notifyAll()
Answer: b
3.Which of these keywords can be used to prevent inheritance of a class?
a) private
b) constant
c) protected
d) final
Answer: final
class can have default and public access modifiers only.A class cant be declared as private
4.Which of these keywords cannot be used for a class ?
a) abstract and final
b) extends and implements
c) abstract and extends
d) none of the above
Answer:a
An abstract class is incomplete one and must be extended by any class.
So we cant declared an abstract class as final.
5.What are the techniques to make a class not inheritable.
a)declaring class as final
b) declaring the constructor as private
c)declaring class with default access modifier
d) a and b
Answer: d
6.What is true about is-a relation ship?
a) Is-A relationship is completely an inheritence
b)The Child class is a type of Parent class
c)Parent class reference variable can refer Child class object
d) All of the above
Answer:d
7.what is true about Has-A relationship?
a)Has-A relationship is a composition
b)Composition means creating instances to other objects
inside a class
c)A class may have many references to other objects
d) All of the above.
Answer:d
8.Which option that best describes the following code:
class Trainee extends Student {
}
a)Student is the base class and Trainee is the sub clas
b)Trainee is the sub class
c)Student is the base class and Trainee is the sub clas
java.lang.Object is base class for Student
d)None of the above
Answer:c
9.Which describes the best of the following code:
class Room {
Table table = new Table();
Chair chair=new Chair();
}
a)It's a class with composition
b)Creating instances for other classes in a class
is called composition.
c)It's a feature of Has-A relationship
d)All of the above.
Answer:d
10.What is true about inheritance and composition
a)Inheritence is static and compile time binding
b)Composition- Has-A retaionship is dynamic binding
and decided at run-time
c)Is-A and Has-A relationships are decided at RunTime
d) Both a and b
Answer: d
11.What is true about Aggragation and Compostion.
a) In Aggragation the objects are independent of each other.
b)In Composition the Objects are tightly coupled.
c)In composition if we delete the parent Object the child objects are get deleted.
But in Aggragation,the child objects remain unaffected.
d)All of the above
Answer. d
12.Determine the output:
class student{
public static void main(String[] arg){
student s1=new student();
System.out.println(s1 instanceof student);
System.out.println(s1 instanceof Object);
}
}
a)true,false
b)true,true
c)compile time error
d)false,true
Answer: b
//All classes in java are sub class of java.lang.Object
13. Determine the output
class student1{
public static void main(String[] arg){
student1 s1=null;
System.out.println(s1 instanceof student1);
}
}
a)true
b)NullPointerException-Compile time error
c)false
d)Runtime Exception
Answer: c
14.Determine the output:
class student2{
public static void main(String[] arg){
student2 s2=null;
System.out.println(s2 instanceof student2);
System.out.println(s2 instanceof Object);
}
}
a)false,true
b)false,false
c)Compile time error
d)false, true
Answer: b
15.Determine the output:
class test1{
public static void main(){
System.out.println("test1");
}
}
a)Compile time error
b)Runtime error
c) test1
d)None of the above
Answer: b
// Method overloding in java allows you to write a method with same name.
Here the main method is not with the required signature:
//public static void main(String[] args)
No comments:
Post a Comment