wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

JAVA QUIZ

Total questions: 11

Worksheet time: 13mins

Name
Class
Date
1.

What is the outoput?


class Test {

protected int x, y;

}


class Main {

public static void main(String args[]) {

Test t = new Test();

System.out.println(t.x + " " + t.y);

}

}

a)

0 0

b)

no output

c)

error

2.

What is the output?

class Test

{

public static void main(String[] args)

{

for(int i = 0; 1; i++)

{

System.out.println("Hello");

break;

}

}

}

a)

error

b)

Hello

c)

no output

3.

•Which of the following is a valid declaration of an object of class Box?

a)

a) Box obj = new Box();

b)

b) Box obj = new Box;

c)

c) obj = new Box();

d)

d) new Box obj;

4.

class main_class

{

public static void main(String args[])

{

int x = 9;

if (x == 9)

{

int x = 8;

System.out.println(x);

}

}

}

a)

•a) 9

b)

b) 8

c)

c) Compilation error

d)

d) Runtime error

5.

class box

{

int width;

int height;

int length;

}

class mainclass

{

public static void main(String args[])

{

box obj1 = new box();

box obj2 = new box();

obj1.height = 1;

obj1.length = 2;

obj1.width = 1;

obj2 = obj1;

System.out.println(obj2.height);

}

}

a)

•a) 1

b)

•b) 2

c)

•c) Runtime error

d)

•d) Garbage value

6.

•Which of the following is not a Java features?

a)

•Dynamic

b)

•Architecture Neutral

c)

•Use of pointers

d)

•Object-oriented

7.

public class Test

{

public static void main(String[] args)

{

int temp = 40;

if(temp == 30 && temp/0 == 4)

{

System.out.println(1);

}

else

{

System.out.println(2);

}

}

}

a)

a) 1

b)

b) 2

c)

c) Runtime Exception of java.lang.ArithmeticException

d)

d) Compilation error due to divisibility by 0

8.

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);

}

}

a)

1

b)

2

c)

3

d)

4

9.

class comma_operator {

public static void main(String[] args)

{

int sum = 0;

for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)

sum += i;

System.out.println(sum);

}

}

a)

5

b)

6

c)

10

d)

14

10.

class Test {

int a = 10;

static int b = 20;

public

static void main(String[] args)

{

Test t1 = new Test();

t1.a = 100;

t1.b = 200;

Test t2 = new Test();

System.out.println("t1.a =" + t1.a + " t1.b =" + t1.b);

System.out.println("t2.a =" + t2.a + " t2.b =" + t2.b);

}

}

a)

A)t1.a=100 t1.b=200

t2.a=10 t2.b=200

b)

B) t1.a=10 t1.b=200

t2.a=10 t2.b=200

c)

C) t1.a=100 t1.b=200

t2.a=10 t2.b=20

d)

D) t1.a=100 t1.b=200

t2.a=100 t2.b=200

11.

Do you want a Java project as group task.. just like we did in CPP

a)

Yes

b)

No