Syvum Home Page

Home > Quiz Games > Java Programming > Print Preview

Java Programming : Flash Cards I

Formats Info Page Worksheet / Test Paper Quiz Review

Hide all answers   View all answers   Print   Try the Quiz

Learn Java programming through these flash cards.

1. What will be the output of the following code?
byte x = 64, y;
y = (byte) (x << 2);
System.out.println(y);

Answer: 0

2. What will be the output of the following code?
byte b;
double d = 417.35;
b = (byte) d; System.out.println(b);

Answer: 161

3. Given the value of a variable, write a statement, without using if construct, which will produce the absolute value of the variable.
Answer: x = x<0?-x:x;


4. What is wrong with the following code?
switch (x)
{
case 1:
n1 = 10;
n2 = 20;
case 2:
n3 = 30;
break;
n4 = 40;
}

Answer: n4 = 40; is unreachable

5. What will be the output of the following program code?
int m = 100;
int n = 300;
while(++m < --n);
System.out.println(m)
;
Answer: 200

6. What does the following fragment display?
String s = "six:" + 3 + 3;
System.out.println(s);

Answer: six:33

7. What is the output of the following code?
String s;
System.out.println("s = " + s);

Answer: null

8. What is the output of the following code?
String s = new String();
System.out.println("s = " + s);

Answer: s =

9. What is the problem with the following snippet?
class Q9


Answer: (i=10) is the problem

10. What will be the output of the following code snippet?
int x = 10;
int y = 20;
if((x||(x=5)>10)
System.out.println(x);
else
System.out.println(y);

Answer: 10

11. Show the output of the following code:
int a, b;
a = 5;
b = 10;
if(a > 5)
if(b > 5)
{
System.out.println("b is " +b);
}
else
System.out.println("a is " +a);

Answer: a is 5

12. State the output of the following code:
int a = 10;
int b = 5;
if(a > b)
{
if(b > 5)
System.out.println("b is " +b);
}
else
System.out.println("a is " +a);

Answer: No output

13. What is the output of the following code:
int m = 100;
while(true)
{
if(m < 10)
break;
m = m - 10;
}
System.out.println("m is " +m);

Answer: m is 0

14. What is the output of the following code:
int m = 100;
while(true)
{
if(m < 10)
continue;
m = m - 10;
}
System.out.println("m is " +m);

Answer: No output; Infinite loop

15. Use a single line of code, complete the following class so that it returns x+y if the value of x is equal to y, otherwise returns 0:
Public class XY


Answer: return(x == y)?x+y:0;

  Try the Quiz :     Java Programming : Flash Cards I


Contact Info © 1999-2017 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright
Previous
-
Next
-