Java MCQs 2
Java MCQs 2
class MCZ11 {
public static void main (String[] args) {
char a = '\c'; // 1
char b = '\r'; // 2
char c = '\"'; // 3
char d = '\b'; // 4
char e = '\''; // 5
}}
Question 2
class GFM11{
public static void main (String[] args) {
int x,y,z;
System.out.println(x+y+z);
}}
Question 3
class MCZ27 {
public static void main (String[] args) {
char a = '\f'; // 1
char b = '\n'; // 2
char c = '\r'; // 3
char d = '\l'; // 4
char e = '\\'; // 5
}}
Question 4
class GRC4 {public static void main(String[] args) {}} // 1
class GRC5 {public static void main(String []args) {}} // 2
class GRC6 {public static void main(String args[]) {}} // 3
What is the result of attempting to compile and run the above programs?
a. Compile-time error at line 1.
b. Compile-time error at line 2.
c. Compile-time error at line 3.
d. An attempt to run GRC4 from the command line fails.
e. An attempt to run GRC5 from the command line fails.
f. An attempt to run GRC6 from the command line fails.
g. None of the above
Question 5
class MCZ28 {
public static void main (String[] args) {
char a = '\b'; // 1
char b = '\d'; // 2
char c = '\f'; // 3
char d = '\t'; // 4
char e = '\"'; // 5
}}
Question 6
class GRC7 {public void main(String[] args) {}} // 1
class GRC8 {public void main(String []args) {}} // 2
class GRC9 {public void main(String args[]) {}} // 3
What is the result of attempting to compile and run the above programs?
a. Compile-time error at line 1.
b. Compile-time error at line 2.
c. Compile-time error at line 3.
d. An attempt to run GRC7 from the command line fails.
e. An attempt to run GRC8 from the command line fails.
f. An attempt to run GRC9 from the command line fails.
Question 7
class MCZ29 {
public static void main (String[] args) {
char a = '\a'; // 1
char b = '\b'; // 2
char c = '\f'; // 3
char d = '\n'; // 4
char e = '\r'; // 5
}}
Question 8
class MCZ30 {
public static void main (String[] args) {
char a = '\t'; // 1
char b = '\\'; // 2
char c = '\?'; // 3
char d = '\"'; // 4
char e = '\''; // 5
}}
Question 9
Which of these words belongs to the set of Java keywords?
a. qualified
b. record
c. repeat
d. restricted
e. label
f. to
g. type
h. until
i. value
j. virtual
k. xor
l. None of the above
Question 10
class JJF1 {
public static void main (String args[]) {
System.out.print(Byte.MIN_VALUE+",");
System.out.print(Byte.MAX_VALUE);
}}
What is the result of attempting to compile and run the program?
a. Prints: 0,255
b. Prints: 0,256
c. Prints: -127,128
d. Prints: -128,127
e. Compile-time error
f. Run-time error
g. None of the above
Question 11
class GRC1 {public static void main(String[] args) {}} // 1
class GRC2 {protected static void main(String[] args) {}} // 2
class GRC3 {private static void main(String[] args) {}} // 3
Question 12
class JJF2 {
public static void main (String args[]) {
System.out.print(Short.MIN_VALUE+",");
System.out.print(Short.MAX_VALUE);
}}
Question 13
class JJF3 {
public static void main(String args[]) {
System.out.print(Integer.toBinaryString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toOctalString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toString(Byte.MAX_VALUE)+",");
System.out.print(Integer.toHexString(Byte.MAX_VALUE));
}}
Question 14
class JJF4 {
public static void main(String args[]) {
System.out.print(Long.toHexString(Byte.MAX_VALUE)+",");
System.out.print(Long.toHexString(Character.MAX_VALUE)+",");
System.out.print(Long.toHexString(Short.MAX_VALUE));
}}
Question 15
class JJF5 {
public static void main(String args[]) {
System.out.print(Integer.toHexString(Integer.MIN_VALUE)+",");
System.out.print(Integer.toHexString(Integer.MAX_VALUE));
}}
Question 16
Which of these words belong to the set of Java keywords?
a. transient
b. serializable
c. runnable
d. run
e. volatile
f. externalizable
g. cloneable
Question 17
class GFM12 {
static int x; // 1
public static void main(String[] args) { // 2
int y; // 3
System.out.println("x="+x); // 4
System.out.println("y="+y); // 5
}}
Question 18
class GFM13 {
static byte a; static short b; static char c;
static int d; static long e; static String s;
public static void main(String[] args) {
System.out.println(a+b+c+d+e+s);
}}
Question 19
class GFM14 {
static byte a; static short b; static char c;
static int d; static long e; static String s;
public static void main(String[] args) {
System.out.println(a+","+b+","+(int)c+","+d+","+e+","+s);
}}
Question 20
class GFM15 {
static int a; static float b; static double c;
static boolean d; static String s;
public static void main(String[] args) {
System.out.println(a+","+b+","+c+","+d+","+s);
}}
Question 21
Which of these words belong to the set of Java keywords?
a. virtual
b. goto
c. ifdef
d. typedef
e. friend
f. struct
g. implements
h. union
i. const
Question 22
Which of these lists contains at least one word that is not a Java keyword?
a. abstract, default, if, private, this
b. do, implements, protected, boolean, throw
c. case, extends, int, short, try
d. import, break, double, exception, throws
e. byte, else, instanceof, return, transient
f. None of the above
Question 23
Which of these lists contains at least one word that is not a Java keyword?
a. interface, static, void, catch, final
b. char, strictfp, finally, long, volatile
c. native, super, class, float, while
d. const, for, new, switch, import
e. continue, finalize, goto, package, synchronized
f. None of the above
Question 24
class Identifiers {
int i1; // 1
int _i2; // 2
int i_3; // 3
int #i4; // 4
int $i5; // 5
int %i6; // 6
int i$7; // 7
int 8i; // 8
}