Friday, January 15, 2010

III. Each Question Carries 4 Mark.
1) class Luck
{
public static void main(String args[]) {
System.out.println(“Best of Luck ”); } }

a) Best of Luck b) Compile error c) runtime error d) None

2) char ch = ‘Z’;
char dy;
dy = ch--;
System.out.println(dy);

a) Z b) Y c) C d) D

3) byte b = 150;
b = (byte) (b * 2);
System.out.println(b);

a) 300 b) Error c) 150 d) None

4) class incdec
{
public static void main(String[]args)
{
int x1=5;
int y1;
y1=x1++;
System .out .println(“x1=”+x1 +“y1=”+y1);
}
}

a) x=5,y=6 b) x=5y=5 c) x=6,y=5 d) x=6,y=6

5) class assign
{
public static void main(String[] args)
{
byte b;
int i=127;
b=i;
System.out.println(b);
}
}

a) Compiler error b) 127 c) runtime error d) None

6) Which of the following is correct
a) 128>>>1 gives 64 b) 128<<1 gives 64 c) 128>>1 gives -64 d) 1128>>>1 gives -64



7) The short hand operator a*=n+1 means
a) a=a*(n+1) b) a=a+n+1 c) n=a+1 d) a +n=1

8) Switch(6)
{
case 5: System.out.println(“five”);
case 6: System.out.println(“six”);
default :System.out .println(“default”);
}

a) six default b) six c) default d)None

9) class abc
{
public static void main(string[]argd)

{
byte a,b,c;
a=10;
b=20;
c=a+b;
System.out.println(“sum of a and b is “+c);
}
}
output of the program

a) 30 b) no output c) compile error d) runtime error

10) class xyz
{
public static void main(String args[])
{
string s1=args[0];
string s2=args[1];

if the program is executed by giving java xyz 10 20________
id the output

a) 1020 b) 30 c) 102030 d) none

11) class xyz
{ static
{
system.out.println(“hello world”);
}
}
a) Executes successfully with a warning of main not found
b) Hello world
b) Gives error
c) Compiles successfully

12) class continur
{
public static void main(String[]args)
{
int n=5;
int I;
for(I=1;I<=n;I++)
{if(I%2==0)
continue;
system.out.println(i);
}
}
}

The output of the program
a) 1 3 5 b) 4 c) 5 d) error



13) Match the following
I ) long A) 64
II) int B) 32
III) short C) 16
IV) byte D) 8

a) I-A,II-B,III-C,IV-D b) I-B,II-C,III-A,IV-D c) I-A,II-D,III-B,IV-C d) None

14) String sum = “five”+ 5 + 5;
System.out.println(sum);

a) five55 b) five 10 c) 15 d) None

15) int x = 1;
switch(x)
{ case 0 : System.out.print("zero");
case 1 : System.out.print("one ");
case 2 : System.out.print("two ");
case 3 : System.out.print("three ");
default : System.out.print("Default ");
}
a) one, two, three, Default b) one
c) one, two, three d) zero,one, two, three, Default


III. Answer – 4 Mark.

1. A 2. B 3. B 4. C 5. A 6. C 7. A
8. A 9. C 10. A 11. B 12. A 13. A 14. A
15. A