MCQ's
MCQ's
MCQ's
5) Which of the following collection objects, we can retrieve the elements in insertion order?
Ans) ArrayList
Vector
6) Class Test1{
Static void display()throws Exception{
System.ou.println(“Hello”);
}
Public static void main(String[] agrs){
Display();
}
}
Which two are the solutions to fix the compilation error in the above program?
Ans) “throws Exception” is declared in method display(). But it does not throw any Exception
within it.
Method display is incorrectly declared.
7) The sleep(int n) method of Thread class is used to pause the execution of the tthread. The
parameter ‘n’ is measured in _____________
Ans) Milli-second.
Class MainClass{
Boolean var1=true;
Boolean var2=false;
If(var1)
System.out.println(var1);
Else
System.out.println(var2);
Ans) TRUE
12) Which one of the following is the only method of runnable interface?
Ans: run()
13) From which interface the class stack e is implemented from?
Ans: List<E>
14) Which of the following is a valid class name as per coding standards in java?
Ans: MainClass
22) When a class A implements an interface B. what type of relation is created between
them?
ANS: A is-a B
28) Two methods having same name and parameter signature, each appearing in base and delivered
classes.
ANS: Overriding
29) class D{
}
class T{
D d;
public Object getD(){ //line 1
return new D(); //line 2
}
}
class S extends T{
@Override
public D getD(){ //line 3
return new D();
}
}
What is the result of compiling the above code?
ANS: Code will have compilation error at line 3
Import java.*;//L1
Public abstract class internalLogic { //L2
Float density = 20.0;//L3
Void do() { //L4
//lot of valid code
Ans: L1,L2,L3,L4
Ans: 0
Ans: float f = 1F
Ans: De- allocate the memory consumed by the objects which are no more required.
36) Which one of the following in java works like a container, which holds a collection of classes,
interfaces and enumes.
Ans: Package
Class Test{
Public static void main(String[] args) {
int option = 1;
if(option = 1) //L1
System.out.print(“Java is simple”);
else
System.out.print(“Java is complex”);
}
}
Ans: Compilation error at line L1
38) Which access modifier hides data/methods completely from the outside world?
Ans: protected
40) Two methods having same name and parameter signature, each appearing in base and
derived classes. The above scenario can be classified under___________
Ans: Hiding
Ans: New object need to be created every time we try to modify the state of the object. So it
consumes more resources
43) What will happen when you compile and execute the following class?
public class Program{
public static void main(){
System.out.println("Hello");
}
}
ANS: Code will compile but throws an exception at runtime(Main method not found in class
Program)
Ans) result+a+b+c;
48) Which one of the following array initialization will cause a compiler error?
ANS: int[][]scores=[2,7,6][9,3,45];
49) Operator = = works with which of the following comparison?
ANS: Compare two objects of different types.
50) Which one of the following array declaration and installation is illegal?
ANS: int a[][]=new int[5][4];
51) There is exactly one copy of this variable exists, regardless of how many times the class has
been instantiated.
ANS: static variable
55) Which two of the following are valid declaration of the standard main() method?
ANS: public static void main(String[] args){}
Public static public void main(String[] arguments){}
56) Which one of the following is true about the finally block?
ANS: Will be always executed whether exception is thrown or not.
58) How many command line arguments can be passed to main() method in java?
ANS: Theoretically unlimited
59)class Base{
Private Base(){
System.out.print(“Base”);
}
}
Public class test extends Base{
Public Test(){
System.out.println(“Derived”);
}
Public static void main(String[] args){
New Test();
}
}
ANS: Compilation error
59) Identify two important methods of the exception class that are helpful for debugging the
code.
ANS: printStackTrace()
60)