- Which of these are legal identifiers. Select the three
correct answers.
- number_1
- number_a
- $1234
- –volatile
- Answer- .A,B xy+abc
- transient
- account-num
- very_long_name
Answer- .A,C,D,E
- Which of the following are keywords in Java. Select the
two correct answers.
- friend
- NULL
- implement
- synchronized
- throws
Answer- .D,E
- Which of the following are Java keywords. Select the
four correct answers.
- super
- strictfp
- void
- synchronize
- instanceof
Answer- . A,B,C,E,. Please
note that strictfp is a new keyword in Java 2.
- Which of these are Java keywords. Select the five
correct answers
- TRUE
- volatile
- transient
- native
- interface
- then
- new
Answer- .B,C,D,E,G
- Using up to four characters, write the Java
representation of octal literal 6.
Answer- . Any of the
following are correct answers - 06, 006, or 0006
- Using up to four characters, write the Java
representation of integer literal 3 in hexadecimal.
Answer- Any of the following
are correct answers - 0x03, 0X03, 0X3 or 0x3.
- Using up to four characters, write the Java
representation of integer literal 10 in hexadecimal.
Answer- . Any of the
following are correct answers - 0x0a, 0X0a, 0Xa, 0xa, 0x0A, 0X0A, 0XA, 0xA
- What is the minimum value of char type. Select the one
correct answer.
- 0
- -215
- -28
- -215 - 1
- -216
- -216 – 1
Answer- .A
- How many bytes are used to represent the primitive data
type int in Java. Select the one correct answer.
- 2
- 4
- 8
- 1
- The number of bytes to represent an int is compiler
dependent.
Answer- .B
- What is the legal range of values for a variable
declared as a byte. Select the one correct answer.
- 0 to 256
- 0 to 255
- -128 to 127
- -128 to 128
- -127 to 128
- -215 to 215 - 1
Answer- .C
- The width in bits of double primitive type in Java is
--. Select the one correct answer.
- The width of double is platform dependent
- 64
- 128
- 8
- 4
Answer- . B
13. What would happen when the following is
compiled and executed. Select the one correct answer.
1.
2.
public class Compare {
3.
public static void main(String args[]) {
4.
int x = 10, y;
5.
if(x < 10)
6.
y = 1;
7.
if(x>= 10) y = 2;
8.
System.out.println("y is " + y);
9.
}
10.}
11.
- The program compiles and prints y is 0 when executed.
- The program compiles and prints y is 1 when executed.
- The program compiles and prints y is 2 when executed.
- The program does not compile complaining about y not
being initialized.
- The program throws a runtime exception.
Answer- .D. The variable y is
getting read before being properly initialized.
14. What would happen when the following is
compiled and executed. Select the one correct answer.
1.
2.
class example {
3.
int x;
4.
int y;
5.
String name;
6.
public static void main(String args[]) {
7.
example pnt = new example();
8.
System.out.println("pnt is " +
pnt.name +
9.
" " + pnt.x + " "
+ pnt.y);
10. }
11.}
12.
- The program does not compile because x, y and name are
not initialized.
- The program throws a runtime exception as x, y, and
name are used before initialization.
- The program prints pnt is 0 0.
- The program prints pnt is null 0 0.
- The program prints pnt is NULL false false
Answer- .D. Instance variable
of type int and String are initialized to 0 and null respectively.
15. The initial value of an instance variable of
type String that is not explicitly initialized in the program is --. Select the
one correct answer.
A.
null
B.
""
C.
NULL
D.
0
E.
The instance variable must be
explicitly assigned.
Answer- .A
16. The initial value of a local
variable of type String that is not explicitly initialized and which is defined in a member function of a class.
Select the one correct answer.
A.
null
B.
""
C.
NULL
D.
0
E.
The local variable must be explicitly
assigned.
Answer- .E
17. Which
of the following are legal Java programs. Select the four correct answers.
A.
//
The comments come before the package
package pkg;
import java.awt.*;
class C{}
B.
package pkg;
import java.awt.*;
class C{}
C.
package
pkg1;
package pkg2;
import java.awt.*;
class C{}
D.
package pkg;
import java.awt.*;
E.
import java.awt.*;
class C{}
import java.awt.*;
package pkg;
class C {}
Answer-A,B,D,E
18. Which of the following statements are
correct. Select the four correct answers.
a.
A Java program must have a package
statement.
b.
A package statement if present must
be the first statement of the program (barring any comments).
c.
If a Java program defines both a
package and import statement, then the import statement must come before the package
statement.
d.
An empty file is a valid source
file.
e.
A Java file without any class or
interface definitions can also be compiled.
f.
If an import statement is present,
it must appear before any class or interface definitions.
Answer- .B,D,E,F
19. What would be the results of compiling and
running the following class. Select the one correct answer.
1.
2. class test {
2.
public static void main() {
3.
System.out.println("test");
4.
}
5.
}
6.
a.
The program does not compile as
there is no main method defined.
b.
The program compiles and runs
generating an output of "test"
c.
The program compiles and runs but
does not generate any output.
d.
The program compiles but does not
run.
Answer- .D
20. Which of these are valid declarations for the
main method? Select the one correct answer.
A.
public void main();
B.
public static void main(String
args[]);
C.
static public void main(String);
D.
public static void main(String );
E.
public static int main(String
args[]);
Answer- .B
21. Which of the
following are valid declarations for the main method. Select the three correct
answers.
a.
public static void main(String
args[]);
b.
public static void main(String
[]args);
c.
final static public void main
(String args[]);
d.
public static int main(String
args[]);
e.
public static abstract void
main(String args[]);
Answer- .A,B,C
22. What happens when the following program is
compiled and executed with the command - java test. Select the one correct
answer.
1.
2.
class test {
3.
public static void main(String args[]) {
4.
if(args.length > 0)
5.
System.out.println(args.length);
6.
}
7.
}
8.
a.
The program compiles and runs but
does not print anything.
b.
The program compiles and runs and
prints 0
c.
The program compiles and runs and
prints 1
d.
The program compiles and runs and
prints 2
e.
The program does not compile.
Answer-A
23. What is the result of compiling and running this program?
Select the one correct answer.
1.
2.
public class test {
3.
public static void main(String args[]) {
4.
int i, j;
5.
int k = 0;
6.
j = 2;
7.
k = j = i = 1;
8.
System.out.println(k);
9.
}
10.}
11.
12.
a.
The program does not compile as k is
being read without being initialized.
b.
The program does not compile because
of the statement k = j = i = 1;
c.
The program compiles and runs
printing 0.
d.
The program compiles and runs
printing 1.
e.
The program compiles and runs
printing 2.
Answer- .D
24. What gets printed on the standard output when
the class below is compiled and executed by entering "java test lets see
what happens". Select the one correct answer.
1.
2.
public class test {
3.
public static void main(String args[]) {
4.
System.out.println(args[0]+"
"+args[args.length-1]);
5.
}
6.
}
7.
a.
The program will throw an
ArrayIndexOutOfBounds exception.
b.
The program will print "java
test"
c.
The program will print "java
happens";
d.
The program will print "test
happens"
e.
The program will print "lets
happens"
Answer- .E
25. What gets printed on the standard output when
the class below is compiled and executed by entering "java test lets see
what happens". Select the one correct answer.
1.
2.
public class test {
3.
public static void main(String args[]) {
4.
System.out.println(args[0]+"
"+args[args.length]);
5.
}
6.
}
7.
a.
The program will throw an
ArrayIndexOutOfBounds exception.
b.
The program will print "java
test"
c.
The program will print "java
happens";
d.
The program will print "test
happens"
e.
The program will print "lets
happens"
Answer- .A
26.
What all gets printed on the
standard output when the class below is compiled and executed by entering
"java test lets see what happens". Select the two correct answers.
1.
2.
public class test {
3.
public static void main(String args[]) {
4.
System.out.println(args[0]+"
"+args.length);
5.
}
6.
}
7.
a.
java
b.
test
c.
lets
d.
3
e.
4
f.
5
g.
6
Answer- .C,E
27.
What happens when the following program is
compiled and run. Select the one correct answer.
1.
2.
public class example {
3.
int i = 0;
4.
public static void main(String args[]) {
5.
int i = 1;
6.
i = change_i(i);
7.
System.out.println(i);
8.
}
9.
public static int change_i(int i) {
10. i = 2;
11. i *= 2;
12. return i;
13. }
14.}
15.
a.
The program does not compile.
b.
The program prints 0.
c.
The program prints 1.
d.
The program prints 2.
e.
The program prints 4
Answer- .. E
28.
What happens when the following program is
compiled and run. Select the one correct answer.
1.
2.
public class example {
3.
int i = 0;
4.
public static void main(String args[]) {
5.
int i = 1;
6.
change_i(i);
7.
System.out.println(i);
8.
}
9.
public static void change_i(int i) {
10. i = 2;
11. i *= 2;
12. }
13.}
14.
a.
The program does not compile.
b.
The program prints 0.
c.
The program prints 1.
d.
The program prints 2.
e.
The program prints 4
Answer- .. C
29.
What happens when the following
program is compiled and run. Select the one correct answer.
1.
2.
public class example {
3.
int i[] = {0};
4.
public static void main(String args[]) {
5.
int i[] = {1};
6.
change_i(i);
7.
System.out.println(i[0]);
8.
}
9.
public static void change_i(int i[]) {
10. i[0] = 2;
11. i[0] *= 2;
12. }
13.}
14.
a.
The program does not compile.
b.
The program prints 0.
c.
The program prints 1.
d.
The program prints 2.
e.
The program prints 4.
Answer- .E
30.
What happens when the following
program is compiled and run. Select the one correct answer.
1.
2.
public class example {
3.
int i[] = {0};
4.
public static void main(String args[]) {
5.
int i[] = {1};
6.
change_i(i);
7.
System.out.println(i[0]);
8.
}
9.
public static void change_i(int i[]) {
10. int j[] = {2};
11. i = j;
12. }
13.}
14.
a.
The program does not compile.
b.
The program prints 0.
c.
The program prints 1.
d.
The program prints 2.
e.
The program prints 4.
Answer- .C