Java MCQ
Java MCQ
Java MCQ
Mary's teacher ask her to find, "s" comes under which type of variable from the below
code
class Sample
{
public void show()
{
System.out.println("Hello Java");
}
}
Class Mainclass
{
Public static void main(String ar[])
{
Sample s;
s =new Sample();
s.show();
}
}
Which of the following is true about "s"
"s" is an object
Abstract Class
Inner Class
Static Class
Q3.
Jane was assigned the task to identify the invalid argument type for main() method
help him to complete the task.
String[] args
String args[]
String args
String[] ar
Q4.
Consider the following statement that represents a relationship: �Shyam has a best
friend who is a Tee�: Which of the following option represents the above relationship
correctly?
class Shyam { private Tee bestFriend; }
Inheritance
Constructor
Dynamic Binding
Q6.
6) In Hotel Atlanta the expensive suit room is 203 The furniture in the suit room 203 is
very attractive Find the types of relationship incorporate in the above sentences
between suit room 203 and Hotel Atlanta,Suit room 203 and furniture Statement 1: Suit
room 203 and Hotel Atlanta Statement 2: Suit room 203 and furniture
Statement 1 is Inheritance and Statement 2 is Aggregation
class
char
void
String
Q9.
class Child implements Account { int a=22; private void getAccountNo(int a) {
System.out.println(a); } } public class Puppy { public static void main(String []args){
Child c=new Child(); c.getAccountNo(12); } }
12
22
something*/ } }
something*/
public }}
class Manager extends Employee implements Inter { public void
private level access is applicable for both classes and its members
Danny 6
Tommy 2
Danny 8
Q13.
Consider the following code: class Student { private String name; public Student() { }
public Student(String name) { this.name = name; this(); } } Which of the following
statement is true regarding the above code?
Compiles successfully without any error
The this can be used only for accessing the member data and member
final
protected
static
Q15.
public class Test{ public static void main(String ar[]){ try{ return; } finally{
System.out.println("Finally"); } } } Select the correct answer from the given options
The program runs and prints nothing
The code will not compile because the catch block is missing
Q16.
public class Test{ int a//____insert code______________ void methodA(){ for(int
i=0;i<="" p="" style="box-sizing: border-box; box-shadow: black 0px 0px; margin:
0px; padding: 0px;">
int a[]={12,23,45,23};
Object
Inheritance
Abstraction
Q19.
Rita want to limit access to a method of a public class to members of the same class.
Which access modifier accomplishes this objective?
public
private
protected
Transient
Q20.
Anithi is from a small village and she went to her aunt�s house in town which is very
far from her house. In her aunt�s house she watched the Television programs she
learnt to operate the television .One day there was a problem with picture tube of the
television and she continuously switched on and switched off the Television without
knowing about the exact problem .The reason is she knows only to switch on,Off
,reduce and increase the volume of TV. Identify the type of oops concept incorporates
in the above case study
Class
Object
Inheritance
Abstraction
Q21.
abstract class Bike { abstract void run(); } class Honda ____________/* statement 1 */
{ void run() { System.out.println("running safely.."); } public static void main(String
args[]){ Bike obj = new Honda (); obj.run(); } } Choose and fill up the appropriate
code in the blank statement
implement Bike
implements Bike
extends Bike
extend Bike
Q22.
Ram ask his Team member �Reta� to create a class which should have accesss to
members of another class in the same package.Which is the most restrictive access
modifier that will accomplish that will accomplish this objective?
public
private
protected
default
Q23.
Which of the following option gives the name of the Exception which is thrown when a
String with Non-Numeric value is parsed with Integer.valueOf() method?
NumberFormatException
IllegalArgumentException
ParseException
ArithmeticException
Q24.
Consider the following listed items: A. Employee() { } B. public Employee() { } C.
private Employee() { } Consider the following statements: I. no-argument constructor,
that does not allow instantiation from within the package II. no-argument constructor,
that does not allow instantiation from outside the package III. no-argument constructor
Which of the following option gives the exact matches of above listed items and
statements?"
A-II, B-III, C-I
Compilation Failed
Throws Exception
Runtime Error
Q26.
What will happen if run the following code? class Q2 { public static void main(String
ar[]) { Boolean[] b1 = new Boolean[10]; boolean[] b2 = new boolean[10];
System.out.println("The value of b1[1] = " +b1[1]); System.out.println("The value of
b2[1] = " +b2[1]); } }
Prints "The value of b1[1] = false" "The value of b2[1] = false".
Compilation error.
Q28.
48) Consider the following code snippet: Integer i=1411, j=i; System.out.println(i++);
System.out.println(++j); Which of the following option gives the correct number of
Auto-boxing and Auto-Unboxing occurred in the above code?
Auto-boxing: 4, Auto-Unboxing: 3
Auto-boxing: 3, Auto-Unboxing: 2
Auto-boxing: 1, Auto-Unboxing: 0
Auto-boxing: 2, Auto-Unboxing: 0
Q29.
Consider the following code: public class TestOverloading { int length(String s) { return
s.length(); } float _length(String s) { return (float) s.length(); } } Which of the following
statement is true regarding the above code?
Both the length() methods are duplicated methods
The this can be used only for accessing the member data and member
10
11
Compilation fails
Q32.
47) Consider the following statement that represents a relationship: �Shyam has a
best friend who is a Tree�: Which of the following option represents the above
relationship correctly?
class Shyam implements Tree { }
In the above picture we can see Tourists are enjoying the thrill ride. If a person should
ride in the thrill rider mandate to have the seat locks. Map the above scenario with
exception handling concept and select the correct option.
Unchecked Exception
Checked Exception
Error
system
unit
module
Q37.
what are some characteristics of a good test
can be run in any order
schedule, estimation
TestNG
Cactus
@Before
@BeforeClass
@AfterClass
Q41.
Which statements below are true about Junit
It is a open source testing framework
Runs a bunch of tests and reports their results
functionality is to check that the two objects refer to the same object.
functionality is to check that the two objects do not refer to the same
object.
Test Fixture
Annotation
unit test
performance
load
Q46.
Identify valid test case
@Test public void testPrintMessage(){
assertEquals(message,printmessage()); ]
@BeforeTest public void testPrintMessage(){
assertEquals(message,printmessage()); ]
@SampleTest public void testPrintMessage(){
assertEquals(message,printmessage()); ]
@Test public int testPrintMessage(){
assertEquals(message,printmessage()); ]
Q47.
Pointers you should consider while creating a test method
Test method must not throw any exception
unit.framework
framework
junit.framework
Q49.
What should be the return type of a test method
Object
Object[]
void
int
Q50.
What is the correct order of execution 1.Test 2.BeforeClass 3.AfterClass 4.Before 5.After
24153
12345
54321
32451
7/20/22, 1:09 PM Hexaware
Attempt 1
Rank: NA Rank: NA
Extends
Implements CORRECT
Inherit
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 1/8
7/20/22, 1:09 PM Hexaware
None
true
false CORRECT
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 2/8
7/20/22, 1:09 PM Hexaware
[2=A, null=B]
CompileTime Exception
[2=A, null=null]
O(n) CORRECT
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 3/8
7/20/22, 1:09 PM Hexaware
O(n*n)
O(1)
Can't be determined
Given the following code snippet, what is the value of movieRating after it is executed?
1 int characters = 5;
2 int story = 3;
3 double movieRating = characters <= 4 ? 3 : story>1 ? 2 : 1;
2.0 CORRECT
3.0
Exception
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 4/8
7/20/22, 1:09 PM Hexaware
Which two operators would be used to test if a number is equal to or greater than 5.21 but
strictly less than 8.1?
ABC
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 5/8
7/20/22, 1:09 PM Hexaware
If a try statement has catch blocks for both Exception and IOException, then which of the
following statements is correct?
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 6/8
7/20/22, 1:09 PM Hexaware
If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class
constructor will be called first if the object of E or D is created?
A CORRECT
A and B
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 7/8
7/20/22, 1:09 PM Hexaware
https://eiphexaware.examly.io/result?testId=U2FsdGVkX1%2F8NyscSNN%2FpN%2FadqpaOD9V2jrZ0iinsMXzNG3Xrv8etX1SWSZip6yx 8/8