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 results in an error at run-time. |
| e. | An attempt to run GRC8 from the command line results in an error at run-time. |
| f. | An attempt to run GRC9 from the command line results in an error at run-time. |
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
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | None of the above |
// Class A is declared in a file named A.java.
package com.dan.chisholm;
public class A {
public void m1() {System.out.print("A.m1, ");}
protected void m2() {System.out.print("A.m2, ");}
private void m3() {System.out.print("A.m3, ");}
void m4() {System.out.print("A.m4, ");}
}
// Class C is declared in a file named C.java.
package com.dan.chisholm.other;
import com.dan.chisholm.A;
public class C extends A {
public static void main(String[] args) {
C c = new C();
c.m1(); // 1
c.m2(); // 2
c.m3(); // 3
c.m4(); // 4
}}
What is the result of attempting to compile and run the program?
| a. | Prints: A.m1, A.m2, A.m3, A.m4, |
| b. | Compile-time error at 1. |
| c. | Compile-time error at 2. |
| d. | Compile-time error at 3. |
| e. | Compile-time error at 4. |
Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing interface?
| a. | abstract |
| b. | implements |
| c. | final |
| d. | private |
| e. | protected |
| f. | public |
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));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1111111,177,127,7f |
| b. | Prints: 11111111,377,256,ff |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class EBH203 {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = a || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class GFC102 {
public static void main(String[] args) {
byte b1 = -129; // 1
byte b2 = 127; // 2
short s1 = -32768; // 3
short s2 = 32768; // 4
char c1 = -1; // 5
char c2 = 65535; // 6
}}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
class GFC403 {
private static int x=1;
static void m1(int i) {x++; i++;}
public static void main (String[] args) {
int y=3; m1(y);
System.out.println(x + "," + y);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,3 |
| b. | Prints: 2,3 |
| c. | Prints: 1,4 |
| d. | Prints: 2,4 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
A class can not be called "tightly encapsulated" unless which of the following is true?
| a. | The class is declared final. |
| b. | All local variables are declared private. |
| c. | All method parameters are declared final. |
| d. | No method returns a reference to any object that is referenced by an internal data member. |
| e. | None of the above |
Which of the following methods are deprecated members of the Thread class?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | resume |
| e. | run |
| f. | sleep |
| g. | start |
| h. | stop |
| i. | suspend |
| j. | yield |
| k. | wait |
class SRC104 {
public static void main (String[] args) {
System.out.print(Math.round(Float.NaN));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: NaN |
| b. | Prints: 0.0 |
| c. | Prints: 0 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class D {
public static void main (String args[]) {
Byte a = new Byte("1");
byte b = a.byteValue();
short c = a.shortValue();
char d = a.charValue();
int e = a.intValue();
long f = a.longValue();
float g = a.floatValue();
double h = a.doubleValue();
System.out.print(b+c+d+e+f+g+h);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 7 |
| b. | Prints: 7.0 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class A {
public static void main (String args[]) {
Integer i1 = new Integer(1);
Integer i2 = new Integer(i1);
System.out.print(i1.equals(i2));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false |
| b. | Prints: true |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class C {
public static void main (String args[]) {
Long a = new Long(1);
byte b = a.byteValue();
short s = a.shortValue();
char c = a.charValue();
int d = a.intValue();
long e = a.longValue();
float f = a.floatValue();
double g = a.doubleValue();
System.out.print(b+s+c+d+e+f+g);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 7 |
| b. | Prints: 7L |
| c. | Prints: 7.0 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class B {
public static void main (String args[]) {
Double a = new Double(0xFFFF);
byte b = a.byteValue();
short c = a.shortValue();
int e = a.intValue();
long f = a.longValue();
float g = a.floatValue();
double h = a.doubleValue();
System.out.print(b+","+c+","+ (e+f+g+h == 4 * 0xFFFF));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0xFFFF,0xFFFF,false |
| b. | Prints: 0xFFFF,0xFFFF,true |
| c. | Prints: -1,-1,false |
| d. | Prints: -1,-1,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
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);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 00000null |
| b. | Prints: 00000 |
| c. | Prints: 0null |
| d. | Prints: 0 |
| e. | Prints: null |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class Maroon {
public static void main (String[] args) {
int a = 1; // 1
short b = 1; // 2
long c = 1; // 3
a = c + a; // 4
c = b + a; // 5
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | None of the above |
interface I1 {}
interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Yellow {
public static void main(String args[]) {
Base base = new Sub(); // 1
I1 i1 = base; // 2
Sub sub = (Sub)base; // 3
I2 i2 = (Sub)base; // 4
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
import java.io.Serializable;
class Blue {
public static void main (String args[]) {
int[] i = {1,2,3}; // 1
Serializable s = i; // 2
i = (int [])s; // 3
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at line 1. |
| b. | Run-time error at line 1. |
| c. | Compile-time error at line 2. |
| d. | Run-time error at line 2. |
| e. | Compile-time error at line 3. |
| f. | Run-time error at line 3. |
| g. | None of the above |
class GFC217 {
static String m(int i) {return "int";}
static String m(float i) {return "float";}
public static void main (String[] args) {
long a1 = 1; double b1 = 2;
System.out.print(m(a1)+","+ m(b1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: float,float |
| b. | Prints: float,double |
| c. | Prints: double,float |
| d. | Prints: double,double |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class E {
void printS1(){System.out.print("E.printS1 ");}
static void printS2() {System.out.print("E.printS2");}
}
class F extends E {
void printS1(){System.out.print("F.printS1 ");}
static void printS2() {System.out.print("F.printS2");}
public static void main (String args[]) {
E x = new F(); x.printS1(); x.printS2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: E.printS1 E.printS2 |
| b. | Prints: E.printS1 F.printS2 |
| c. | Prints: F.printS1 E.printS2 |
| d. | Prints: F.printS1 F.printS2 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class C {
private static String s1 = "s1";
String s2 = "s2";
C() {m1("s5","s6");}
void m1(final String s5, String s6) {
final String s3 = "s3"; String s4 = "s4";
class Z {Z() {System.out.print(???);}}
new Z();
}
public static void main(String args[]) {new C();}
}
Which variable names can be substituted for ??? without causing a compile-time error?
| a. | s1 |
| b. | s2 |
| c. | s3 |
| d. | s4 |
| e. | s5 |
| f. | s6 |
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A c1 = new C(); B c2 = new C();
C c3 = new C(); C c4 = new C();
c4.m1(c1); c4.m1(c2); c4.m1(c3);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CCC |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class MWC104 {
public static void main (String[] args) {
char[] c = {'a','b','c','d'};
String s1 = new String(c);
boolean b = true;
for (int i = 0; i < s1.length; i++) {
b &= (c[i] == s1.charAt(i));
}
System.out.print(b);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false |
| b. | Prints: true |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class MWC202 {
public static void main (String[] args) {
StringBuffer sb1 = new StringBuffer("ABC");
StringBuffer sb2 = new StringBuffer("ABC");
System.out.print((sb1==sb2)+","+sb1.equals(sb2));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
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 |
class EBH103 {
public static void main (String[] args) {
byte a = 1, b = 2, c, d, e;
c = (byte)a++;
d = (byte)++b;
e = (byte)a + b;
System.out.print(c + d + e);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 2 3 |
| b. | Prints: 6 |
| c. | Prints: 2 3 5 |
| d. | Prints: 10 |
| e. | Prints: 1 3 4 |
| f. | Prints: 8 |
| g. | Prints: 1 3 5 |
| h. | Prints: 9 |
| i. | Run-time error. |
| j. | Compile-time error. |
| k. | None of the above |
class GFC304 {
static void m1(int[] i1, int[] i2) {
int[] i3 = i1; i1 = i2; i2 = i3;
}
public static void main (String[] args) {
int[] i1 = {1}, i2 = {3}; m1(i1, i2);
System.out.print(i1[0] + "," + i2[0]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,1 |
| b. | Prints: 1,3 |
| c. | Prints: 3,1 |
| d. | Prints: 3,3 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH003 {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
m(m(~1) + m(1|2) + m(1&2) + m(1^3) + m(1<<1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -2, 3, 0, 3, 0, 6 |
| b. | Prints: -2, 3, 0, 2, 1, 4 |
| c. | Prints: -2, 3, 0, 2, 2, 5 |
| d. | Prints: -2, 3, 0, 3, 2, 6 |
| e. | Prints: -1, 3, 0, 3, 2, 7 |
| f. | Prints: -2, 0, 3, 3, 0, 6 |
| g. | Prints: -1, 0, 3, 2, 1, 4 |
| h. | Prints: -2, 0, 3, 2, 2, 5 |
| i. | Prints: -2, 0, 3, 3, 2, 6 |
| j. | Prints: -1, 0, 3, 3, 2, 7 |
| k. | Run-time error |
| l. | Compile-time error |
| m. | None of the above |