Java MCQ Solution
Java MCQ Solution
1. Int I =2;
System.out.println (“welcome”+1+2);
The Output is –
I. Welcome 4
II. Welcome 12
III. Compiler error
IV. None of these
Ans – (ii)
2. Int x=2;
For(x=0;x<5;x++);
System.out.println(x);
The output is –
i. 01234
ii. 1234
iii. 234
iv. 5
Ans – (i)
3. String a=”3”;
System.out.println(a);
The output is –
i. 3
ii. A
iii. Compiler error
Iv runtime exception
Ans – (i)
4. Int a =2;
For( ; a<5 ; a++)
System.out.println(a);
The output is –
i. Compiler error
ii. Runtime execption
iii. Infinite loop
iv. 234
Ans – (iv)
The output is –
i. 3
ii. 7
iii. Compiler error
iv. Runtime exception
Ans – (iv)
Ans – (i)
Ans – (i)
Ans – (i)
9. Strings a = “WBUT”
System.out.println (s.charAt(2));
The output is –
i. U
ii. Exception error
iii. 2
iv. B
Ans – (i)
Ans – (i)
Int a = 10 , b=15
i. 10
ii. 25
iii. 15
iv. 5
Ans – (ii)
Ans – (iv)
Year – 2009
1. Java bytecode is saved in files with names that end with
a. .class
b. .code
c. .java
d. .exe
Ans – (i)
2. An exception is
a. Run time error
b. Machine error
c. Compile time error
d. none of these
Ans – (i)
3. From the following which one is not java primitive data type ?
a. Byte
b. Boolean
c. Short
d. Variant
Ans – (d)
4. The ability to declare different methods with the same name in a class is known as –
a. Method Overloading
b. Method Overriding
c. Recursion
d. None of these
Ans – (a)
Ans – (a)
7. The many catch clause can be try statement have without finally ?
a. One
b. Any number
c. Zero
d. None of these
Ans – (c )
Year – 2010
1. Which of these is known as short – circuit and operator
a. &&
b. &
c. ? &
d. None of these
Ans – (a)
8. Each time we shift a value to the right using ‘>>’ operator it divide the value by –
a. 4
b. 2
c. 8
d. None of these
Ans – (b)
Year – 2011
1. String s = “s”
System.out.println (s);
The Output is –
a. S
b. “s”
c. Compiler error
d. Run time error
Ans – (a)
Int a = 3 , b=2 ;
a. 5
b. -1
c. 1
d. 3
Ans – ( c )
7. An exception is –
a. Run time error
b. Compiler error
c. Machine error
d. None of these
Ans – (a)
8. How many default constructor can a class have , when it has constructor ?
a. 1
b. 0
c. 2
d. Any number
Ans – (a)
What is printed ?
a. 6
b. 7
c. 8
d. Columbia
e. River
Ans – (b)
7. You read the following statement in a java program that compiles and executes
Submarine.drive(depth);
What can you say for sure ?
a. Depth must be an int
b. Drive must be a method
c. Drive must be the name of an instance field
d. Submarine must be the name of class
e. Submarine must be a method
Ans – (b)
}
What is the name of the java file containing this program ?
a. myLibrary.Java
b. ShowSomeClass.java
c. ShowSomeClass
d. ShowSomeClass.Class
e. Any file name with the java suffix will do
Ans – (b)
10. What happens if Database Updation code is written code is written in ejbPassivate() method
and if this method is called ?
a. Exception is thrown
b. Successfully execute the database updation code
c. Compilation error occurs indicating that database updation cod should not be
written in ejbpassivate ()
d. ejbStore () method is called
Ans – (a)
Year – 2014
1. A class can have many methods with the same name as long as the number of the
parameters or type of parameters is different. This OOP concept is know as -------
a. Method invocating
b. Method overriding
c. Method labelling
d. Method overloading
Ans – (d )
3. Which one of the following methods keeps the thread t in run state ?
a. t.start()
b. t.run()
c. t.setRun()
d. t.stop –()
Ans – (a)
10. Method overloading is one of the way that java supports _________________
a. Encapsulation
b. Class
c. Inheritance
d. Polymorphism
Ans – (d )
Year – 2015
1. Which is reserved word in the java programming language ?
a. Method
b. Native
c. Subclass
d. Reference
Ans – (b )
8. An exception is a / an
a. Runtime problem
b. Compile time problem
c. Entity dependent on type
d. None of these
Ans – (A)
The output is –
a. U
b. Exception error
c. 2
d. B
Ans – (a)
Year – 2016
1. Return type of a constructor method is -
a. Int
b. Void
c. Class type itself
d. Nothing, as no specification of return type is needed
Ans – (d)
9. Which of the following is used to detect the selection made by user on a choice component?
a. Action listener
b. Item listener
c. Mouse listener
d. Selection listener
Ans – ( c )
Year – 2017
1. Int x=2;
For ( x=0 ; x<5 ; x++ )
System.out.println (x);
The output is –
a. 01234
b. 234
c. 1234
d. None of these
Ans – (a)
2. How many default constructor can a class have when it has constructor ?
a. 1
b. 0
c. 2
d. Any number
Ans – (1)
6. Which access modifier is used to restrict the methods scope to itself and still allows other
classes to subclass that class ?
a. Private
b. Final
c. Protected
d. Public
Ans – (b )
7. An exception is a / an –
a. Runtime problem
b. Compile time problem
c. Entity dependent on type
d. None of these
Ans – (a )
10. A constructor –
a. Must have the same name as the class it is declared within
b. Is used to cerate objects
c. May be declared private
d. None of these
Ans – (a) , (b)
Year – 2018
1. Which type of polymorphism is nothing but the method overloading in java ?
a. Compile time polymorphism
b. Runtime polymorphism
c. Static polymorphism
d. Both (a) & (b)
Ans – (a)
8. Which method used in thread class to test if the current thread class to test if the current
thread has been interrupted ?
a. Public static Boolean interrupted ()
b. Public Boolean is interrupted ()
c. Public void interrupted
d. Public Boolean is Alive ()
Ans – (a)
10. An exception is –
a. Runtime error
b. Machine error
c. Compile time error
d. None of these
Ans – (a)
Year – 2019
1. Which of the following may be part of a class definition ?
a. Instance variables
b. Instance methods
c. Constructors
d. All of these
Ans – (d)
3. An exception is
a. A runtime error
b. A compile time error
c. A syntactical error
d. None of these
Ans – (A)
a. TestClass.class
b. TestClass.java
c. TestClass.obj
d. None of these
Ans – (b)