NEW
Font size
WorksheetsJAVA QUIZ
Total questions: 11
Worksheet time: 13mins
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);
}
}
0 0
no output
error
What is the output?
class Test
{
public static void main(String[] args)
{
for(int i = 0; 1; i++)
{
System.out.println("Hello");
break;
}
}
}
error
Hello
no output
•Which of the following is a valid declaration of an object of class Box?
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;
class main_class
{
public static void main(String args[])
{
int x = 9;
if (x == 9)
{
int x = 8;
System.out.println(x);
}
}
}
•a) 9
b) 8
c) Compilation error
d) Runtime error
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) 1
•b) 2
•c) Runtime error
•d) Garbage value
•Which of the following is not a Java features?
•Dynamic
•Architecture Neutral
•Use of pointers
•Object-oriented
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) 1
b) 2
c) Runtime Exception of java.lang.ArithmeticException
d) Compilation error due to divisibility by 0
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);
}
}
1
2
3
4
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);
}
}
5
6
10
14
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)t1.a=100 t1.b=200
t2.a=10 t2.b=200
B) t1.a=10 t1.b=200
t2.a=10 t2.b=200
C) t1.a=100 t1.b=200
t2.a=10 t2.b=20
D) t1.a=100 t1.b=200
t2.a=100 t2.b=200
Do you want a Java project as group task.. just like we did in CPP
Yes
No
