0% found this document useful (0 votes)
40 views6 pages

Exam

This document contains a technical exam for Ashok IT with 17 multiple choice questions covering Java fundamentals such as data types, operators, inheritance, memory locations, wrapper classes and methods in Object class. The questions test knowledge of topics like String comparisons, access modifiers, switch statements, subclasses, and more.

Uploaded by

Sudhir Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

Exam

This document contains a technical exam for Ashok IT with 17 multiple choice questions covering Java fundamentals such as data types, operators, inheritance, memory locations, wrapper classes and methods in Object class. The questions test knowledge of topics like String comparisons, access modifiers, switch statements, subclasses, and more.

Uploaded by

Sudhir Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

Welcome To Ashok IT

Technical Exam

Date: 16/10/2022

===================================================================================
=============================
1) If you compile and execute an application with the following code in its main()
method:

String s = new String("Computer");


if(s =="Computer")
System.out.println("Equal A");
if(s.equals("Computer"))
System.out.println("Equal B");

a) It will not compile because the String class does not support the = =
operator.
b) It will compile and run, but nothing is printed.
c) "Equal A" is the only thing that is printed.
d) "Equal B" is the only thing that is printed.
e) Both "Equal A" and "Equal B" are printed.

Answer : _____a_________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
2) If you want a member variable to not be accessible outside the current class at
all,
what keyword should precede the name of the variable when declaring it?

Answer : ________private______________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
3) Consider the below snippet

public static void main(String args[]) {

int a = 5;
System.out.println(cube(a));
}

int cube(int theNum ) {

return theNum * theNum * theNum;


}
What will happen when you attempt to compile and run this code?
a) It will not compile because cube is already defined in the java.lang.Math
class.
b) It will not compile because cube is not static.
c) It will compile, but throw an arithmetic exception.
d) It will run perfectly and print "125" to standard output.

Answer:___a________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
4) Given the variables defined below:
int one = 1;
int two = 2;
char initial = '2';
boolean flag = true;

Which of the following options are valid?

a) if( one ){}


b) if( one = two ){}
c) if( one == two ){}
d) if( flag ){}
e) switch( one ){}
f) switch( initial ){}

Answer:___a______________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
5) If val = 1 in the code below:

switch(val) {

case 1: System.out.print( "P" );

case 2:

case 3: System.out.print( "Q" );


break;

case 4: System.out.print( "R" );

default: System.out.print( "S" );


}

Answer: ____case 1,case,4,default_____________


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
6) int val = 1;

switch(val) {

case 1: System.out.print( "P" );

case 2:

case 3: System.out.print( "Q" );


break;

case 4: System.out.print( "R" );

default: System.out.print( "S" );


}

Which values would be printed?

a) P
b) Q
c) R
d) S
e) PQRS
f) PQ

Answer:_____e___________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
7) Assume that Sub1 and Sub2 are both subclasses of class Super.

Given the declarations:

Super sup = new Super();

Sub1 sub1 = new Sub1();

Sub2 sub2 = new Sub2();

Which statement best describes the result of attempting to compile and execute
the following statement:

sup = sub1;

a) Compiles and definitely legal at runtime

b) Does not compile

c) Compiles and may be illegal at runtime

Answer:____c___________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
8) For the following code:

class Super {

int index = 5;

public void printVal(){

System.out.println( "Super" );
}
}

class Sub extends Super {

int index = 2;

public void printVal(){

System.out.println( "Sub" );
}
}
public class Test {

public static void main( String argv[]){

Super sup = new Sub();


System.out.print( sup.index + "," );
sup.printVal();
}
}
What will be printed to standard output?

a) The code will not compile.

b) The code compiles and "5, Super" is printed to standard output.

c) The code compiles and "5, Sub" is printed to standard output.

d) The code compiles and "2, Super" is printed to standard output.

e) The code compiles and "2, Sub" is printed to standard output.

f) The code compiles, but throws an exception.

Answer : _____e_______________________

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
9) If s1 is declared as:

String s1 = "phenobarbital";

What will be the value of s2 after the following line of code:

String s2 = s1.substring( 3, 5 );

a) null

b) "eno"

c) "enoba"

d) "no"

Answer:____d_______________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
10) You want to limit access to a method of a public class to members of the same
class.Which access accomplishes this objective?

A. public

B. private

C. protected

D. transient

E. default access

Answer:________c_____________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
11) What is the numerical range of a char?

A. 0 ... 32767

B. 0 ... 65535
C. –256 ... 255

D. –32768 ... 32767

E. Range is platform dependent.

Answer:_________b____________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
12) Conside the Below Code

public class X {

public static void main (String[] args) {

byte b = 127;

byte c = 126;

byte d = b + c;
}
}

Which statement is true?

A. Compilation succeeds and d takes the value 253.

B. Line 5 contains an error that prevents compilation.

C. Line 5 throws an exception indicating “Out of range”

D. Line 3 and 4 contain error that prevent compilation.

E. The compilation succeeds and d takes the value of 1.

Answer:_________a_____
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
13) Purpose of Wrapper Classes in Java ?

Answer:__________object creation________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
14) Brief about Widening Typecasting and narrowing Typecasting ?

Answer:__________________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
15) What is parent class for every Java Class ?

Answer:___________object class________________
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++
16) Tell me Memory locations in JVM for below Members

Objects will Stored _____heap____________ memory Location

Static Methods & Fields will be stored_______stack_____________memory


Location
String literals are stored____________contiguous______________memory location

Local Fields are Stored_____________object class_______________memory


location
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
17) How Many No Of Methods are available in java.lang.Object ?

a) 10

b) 11

c) 12

d) 9

Answer:_______b_______
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++

You might also like