You are on page 1of 28

SNO Topics No OF Questions

1 Datatypes 51
2 Control Statement 25
3 Loops 15
4 OOPS 13
5 Classes 56
6 Inheritance 11
7 Overloading - Overrriding 29
8 Abstract Class - Method 31
9 Interface 27
10 Access Control - Package 22
11 Threading 20
12 Collection 50
13 IO Classes 26
14 String 32
15 Exception 15
16 Spring 20
17 Struts 10
18 Serialization 12
19 JSON 5
20 Misc 30
Total 500
Questions
In Java Arrays are

What could be output of the following fragment of code?


public class Test{
public static void main(String args[]){
String x = "hellow";
int y = 9;
System.out.println(x += y);
}
}

What is the output of this program?

class Abc
{
public static void main(String[]args)
{
String[] elements = { "first item", "second item", "third item" };
String first = (elements.length > 0) ? elements[0]: null;
}
}

What is the order of variables in Enum?

Can we create instance of Enum outside of Enum itself?

enum Season {
WINTER, SPRING, SUMMER, FALL
};
System.out.println(Season.WINTER.ordinal());

class array_output
{
public static void main(String args[])
{
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i) {
array_variable[i] = i/2;
array_variable[i]++;
System.out.print(array_variable[i] + " ");
i++;
}

}
}

Which of these is incorrect string literal?


Object[] names = new String[3];
names[0] = new Integer(0);

With x = 0, which of the following are legal lines of Java code for changing the
value of x to 1?
1. x++;

2. x = x + 1;

3. x += 1;

4. x =+ 1;

Which of these statements are incorrect?

6. What is the output of this program?


class increment {
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);

}
}

What is the output of this program?


class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}

What is the output of this program?


class Output {
public static void main(String args[])
{
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + " " + y);
}
}
A) B) C)
Objects Object reference Primitive Datatype

Throws an exception as string


and int are not compatible for
addition hellow9 9hellow

Compilation error An exception is thrown at run time null

Ascending order Descending order Random order

1 0 both

0 1 2

02468 12345 0123456789

“Hello World” “Hello\nWorld” “\”Hello World\””


ArrayIndexOutOfBoundsExceptio
n ArrayStoreException Compilation Error

1, 2 & 3 1&4 1, 2, 3 & 4

Assignment operators are more


efficiently implemented by Java Assignment operators can be used
run-time system than their Assignment operators run faster only with numeric and character
equivalent long forms. than their equivalent long forms. data type.

11 0 1 1.5 1

25 24 32

11 11 10 10 11 10
D) Answer
None of the above A. Objects

Compilation error B.hellow9

first item D.first item

depends on the order() method A.Ascending order

None B.False

3 A.0

1 2 3 4 5 6 7 8 9 10 B.1 2 3 4 5

“Hello D. “Hello
world” world”
Code runs successfully A. ArrayStoreException

3&2 A. 1, 2 & 3

None D.none

1.5 1.0 C. 1.5 1

33 C.32

10 11 C. 11 10
Questions

What would be the output of the following codesnippet if variable a=10?

if(a<=0)
{
if(a==0)
{
System.out.println("1 ");
}
else
{
System.out.println("2 ");
}
}
System.out.println("3 ");
The while loop repeats a set of code while the condition is not met?

Consider Following statement


int x = 10; y=15;
x = ( ( x<y) ? (y+x) : (y-x))
Which of the following loops will execute the body of loop even when condition controlling
the loop is initially false?

class selection_statements
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}

What is the output of this program?

class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
What is the prototype of the default constructor of this class?
public class prototype { }
If an expression contains double, int, float, long, then whole expression will promoted into
which of these data types?
public class Test {
public static void main (String args []) {
boolean a = false;
if (a = true)
System.out.println("Hello");
else
System.out.println("Goodbye");
}
}

public class Test{


public static void main(String args[]){
int i, j=1;
i = (j>1)?2:1;
switch(i){
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}

class Test{
public static void main(String args[]){
int x=7;
if(x==2);
System.out.println("NumberSeven");
System.out.println("NotSeven");
}
}

char ch = 'a';
switch (ch){
case 'a':
case 'A': System.out.print(ch); break;
case 'b':
case 'B': System.out.print(ch); break;
case 'c':
case 'C': System.out.print(ch); break;
case 'd':
case 'D': System.out.print(ch);
}
f(number>=0)

if(number>0)

system.out.println("Number is positive");

else

system.out.println("Number is negative");

What will be the output if number is equal to 0?

char c='a';

switch (c)

{
case 'a';

system.out.println("A");

case 'b';
system.out.println("B");

default;

system.out.println("C");
}
A) B)

1 2 2 3

1 0

25 15

do-while while

1 2

25 24

prototype( ) prototype(void)

long int
Program produces no output but
terminates correctly. Program does not terminate.

1 2

NumberSeven NotSeven NumberSeven

abcd aa
Number is negative Number is positive

Output will be A Output will be A followed by B


C) D)

1 3 3

5 error

for none

3 4

32 33

public prototype(void) public prototype( )

double float
Prints out "Hello" Prints out "Goodbye"

3 1 2

NotSeven Error

a ab
Both A and B None of the above

Output will be A, followed by B, and Code is illegal and therefore


then followed by C will not compile
Answer

D. 3

B. False

A. 25

A. do-while

B. 2

C. 32

D. public prototype( )

C. double
C.Prints out "Hello"

D. 1 2

A.NumberSeven NotSeven

C.a
A) Number is negative

B) Output will be A followed by B


Questions
Which of the following is not OOPS concept in Java?

Which concept of Java is a way of converting real world objects in terms of class?

Which concept of Java is achieved by combining methods and attribute into a class?

What is it called if an object has its own lifecycle and there is no owner?

What is it called where child object gets killed if parent object is killed?

What is it called where object has its own lifecycle and child object cannot belong to another
parent object?

Method overriding is combination of inheritance and polymorphism?

Which of the following is the functionality of 'Data Abstraction'?


Which of the following mechanisms is/are provided by Object Oriented Language to implement
Object Oriented Model?

Which of the these is the functionality of ‘Encapsulation’?


What is ‘Basis of Encapsulation’?
How will a class protect the code inside it?

class Test {
int a;
public int b;
private int c;
}
class AcessTest {
public static void main(String args[])
{
Test ob = new Test();
ob.a = 10;
ob.b = 20;
ob.c = 30;
System.out.println(" Output :a, b, and c" + ob.a + " " + ob.b + " " + ob.c);
}
}
A) B) C)
Inheritance Encapsulation Polymorphism

Polymorphism Encapsulation Abstraction

Encapsulation Inheritance Polymorphism

Aggregation Composition Encapsulation

Aggregation Composition Encapsulation

Aggregation Composition Encapsulation

1 0
Binds together code and
Reduce Complexity data Parallelism

Encapsulation Inheritance Polymorphism

Using single interface for


Binds together code and data general class of actions. Reduce Complexity
object class method
Using Access specifiers Abstraction Use of Inheritance

Compilation error Run time error Output : a, b and c 10 20 30


D) Answer

Compilation D. Compilation

Inheritance C.Abstraction

Abstration A.Encapsulation

Association D.. Association

Association B. Composition

Association
A. Aggregation

A. true

None of the mentioned a) Reduce Complexity

All of the mentioned d) All of the mentioned

All of the mentioned a) Binds together code and data


All of the mentioned D.All of the mentioned
All of the mentioned A. Using Access specifiers

None of the mentioned a) Compilation error

You might also like