Additional text to be added later.
class MyString extends String { }
The code compiles successfully. The code does not compile because you have not defined a main() method. The code does not compile because String is abstract. The code does not compile because String is final
main()
String
final
integer double float default
integer
double
float
default
public protected private default
public
protected
private
abstract class double Boolean
class, double, Boolean class, double abstract, double, class abstract, class, double, Boolean
class
Boolean
abstract
class ClassA { public static void main (String[] args) { ClassB b = new ClassB(); } ClassA (int i) { } } class ClassB extends ClassA { }
The code does not compile because the ClassA class does not define a no-args constructor. The code does not compile because the ClassB class does not define a no-args constructor. The code does not compile because there is no code in the ClassA(int i). The code compiles and runs successfully.
ClassA
ClassB
ClassA(int i)
a byte a short an int a long
byte
short
int
long
-215 to 215-1 -2(number of bits - 1) to 2(number of bits - 1) -231 to 231 -2(number of bits - 1) to 2(number of bits - 1) - 1
class ClassA { int instVar1 = 1; int instVar2; public static void main(String[] args) { int localVar3 = 3; System.out.println(instVar1 + instVar2 + localVar3); } }
4 0 The code does not compile because localVar is not initialized correctly. The code does not compile because instVar2 is not initialized at all.
4
0
localVar
instVar2
boolean[] b = new boolean[3]; boolean[] b = {true, true, true}; boolean[3] b = {true, true, true}; boolean[] b = new boolean[3]; b = {true, true, true};
boolean[] b = new boolean[3];
boolean[] b = {true, true, true};
boolean[3] b = {true, true, true};
boolean[] b = new boolean[3]; b = {true, true, true};
5 & 2
0 2 5 7
2
5
7
10 | 2
0 2 10 14
10
14
if
an integer a boolean either an integer or a boolean none of the above
boolean
char c = 'a'; switch(c) { case 'a': System.out.println("a"); break; default: System.out.println("default"); }
The code will not compile because the switch statement does not have a legal expression. The code will compile and run but nothing will be written to the standard output. The code will compile and run and the letter "a" will be written to the standard output. The code will compile and run and the word "default" will be written to the standard output.
switch
"a"
"default"
int myInt = 3; if (myInt < 5) if (myInt < 3) System.println.out("< 3"); else if (myInt > 2) System.out.println("> 2"); else System.out.println("other');
"< 3" "> 2" "other" nothing
"< 3"
"> 2"
"other"
any line of code only lines of code associated with a loop (just before, at the loop, just after) only the line of code at the start of a loop only the line of code defining the most outer loop
class A { public static void main(String[] args) { try { System.out.println("Hello!"); } } }
You cannot have a try block without a catch and/or finally Code that does not throw an exception cannot be in a try block The method main() must always throw something if the try block is used without a catch.
try
catch
finally
class Over { public static void main (String[] args) { Under u = new Under(); u.test(); } int test() { System.out.println("Over"); return 1; } } class Under extends Over { short test() { super.test(); System.out.println("Under"); return 1; } }
The code does not compile. This code compiles and runs and displays Over followed by Under. This code compiles and runs and displays Under followed by Over.
Over
Under
Math
Math.method(x);
-5
x
-4.5
round() ceil() floor() all of the above round() and floor() only
round()
ceil()
floor()
String s = "Penguin";
c
char c = s.charAt(6)
'n' 'i' Nothing will be assigned because charAt() will respond with a StringIndexOutOfBoundException
'n'
'i'
charAt()
StringIndexOutOfBoundException
class Str { public static void main(String[] args) { String s = new String("HELLO"); String t; t = s.toUpperCase(); if (s == t) System.out.println("equals"); else System.out.println("not equals"); } }
equals not equals
equals
not equals
class Str { public static void main(String[] args) { String s = new String("Hello"); String t; t = s.toUpperCase(0; if (s == t) System.out.println("equals"); else System.out.println("not equals"); } }
String s = "Hello"; String t = s; s += " world"; if (s == t) System.out.println("equals"); else System.out.println("not equals");
It is the only thread currently running. It has been suspended. It has been resumed. It has been notified. All of the above.
Thread.MAX_PRIORITY
The thread with the normal priority will definitely not run until the thread with the maximum priority ends. The thread with the normal priority will never run, even after the thread with the maximum priority ends. Neither of the above is true.
wait()
Thread Applet Object Runnable
Thread
Applet
Object
Runnable
When you first create a thread At any time after you create a thread All of the above
update() paint() init() repaint()
update()
paint()
init()
repaint()
Thread Applet Graphics Component
Graphics
Component
Event
component target evt id
component
target
evt
id
handleEvent() action() both handleEvent() and action() neither of these
handleEvent()
action()
Event and Object Event Object Component
Event and Object
false true null 0
false
true
null
public static void main(String args[]) { } public static void main(String[]) { } public static void main(String[] args) public static void main(args)
public static void main(String args[]) { }
public static void main(String[]) { }
public static void main(String[] args)
public static void main(args)
"blue"
java red blue green blue red
args[1] args[3] args[2] args[4] both args[1] and args[3]
args[1]
args[3]
args[2]
args[4]
lastname
String s = getName("lastname"); String s = parameter("lastname"); String s = getParameter("lastname");
String s = getName("lastname");
String s = parameter("lastname");
String s = getParameter("lastname");
The runtime would throw an exception The parameter's value would be null The parameter's value would be an empty string.
validate() repaint() layout() update()
validate()
layout()
Clonable Throwable RemoteObject Remote
Clonable
Throwable
RemoteObject
Remote
not return a value throw a RuntimeException throw a RemoteException be static methods
RuntimeException
RemoteException
static
a stub representing the object a copy of the object a direct reference to the object an instance of RemoteObject
a port number an IP address both a port number and an IP address none of these
Socket ServerSocket Server URL
Socket
ServerSocket
Server
URL
accept()
Java attempts to establish a connection over the Internet with the host. Java starts a server running on the host. Nothing special happens until you invoke the Socket's accept() method.
Identify a machine on the Internet based on the dotted octet or domain name Ensure packets arrive in the same order they are sent Both previous choices are correct None of the above
class Animal { abstract void growl(); } abstract Animal { abstract void growl(); } class abstract Animal { abstract void growl(); } abstract class Animal { abstract void growl(); } abstract class Animal { abstract void growl() { System.out.println("growl"); } }
class Animal { abstract void growl(); }
abstract Animal { abstract void growl(); }
class abstract Animal { abstract void growl(); }
abstract class Animal { abstract void growl(); }
abstract class Animal { abstract void growl() { System.out.println("growl"); } }
Key
class Key { } abstract final class Key { } native class Key { } class Key { final } final class Key { }
class Key { }
abstract final class Key { }
native class Key { }
class Key { final }
final class Key { }
class Tester { int var; Tester (double var) { this.var = (int)var; } Tester (int var) { this("hello"); } Tester (String s) { this(); System.out.println(s); } Tester () { System.out.println("good-bye"); } public static void main(String[] args) { Tester t = new Tester(5); } }
nothing hello 5 hello followed by good-bye good-bye followed by hello
hello
good-bye
a
j
first
class Riddle { public static void main(String[] args) { String first, second; String riddle; if (args.length < 2) return; a: first = new String(args[0]); b: second = new String(args[1]); c: riddle = "When is a " + first; d: first = null; e: riddle += " like a " + second + "?"; f: second = null; g: System.out.println(riddle); h: args[0] = null; i: args[1] = null; j: } }
d: e: h: i: j:
d:
-27 to 27 - 1 0 to 28 -28 to 28 -27 to 27 - 1 -(28 - 1) to 28
class Array { public static void main(String[] args) { int length = 100; int[] d = new int[length]; for (int index = 0; index < length; index++) System.out.println(d[index]); } }
The code will not compile because the int[] array is not declared correctly. The code will compile but will throw an IndexArrayOutOfBoundsException when it runs and nothing will appear in the standard output The code will display the numbers 0 through 99 in the standard output, and then throw an IndexOutOfBoundsException The code will compile but the println() method will throw a NoSuchMethodException This code will work fine and display 100 zeroes in the standard output.
int[]
IndexArrayOutOfBoundsException
99
IndexOutOfBoundsException
println()
NoSuchMethodException
class Superclass { } class Subclass1 extends Superclass { }
Superclass a = new Superclass(); Subclass1 b = new Subclass1();
a = b
Illegal at compile time Legal at compile time but possibly illegal at runtime Definitely legal at runtime
break
outer: for (int x = 0; x < 3; x++) { middle: for (int y = 0; y < 3; y++) { inner: for (int z = 0; z < 3; z++) { if (arr(x, y, z) == targetValue) break; } } }
break inner break middle break outer continue continue middle
break inner
break middle
break outer
continue
continue middle
b = a;
double a = 90.7; double b = method(a); System.out.println(b);
method()
abs() min() floor() round() ceil()
abs()
min()
(true & true) (4 & 5) (int myInt = 0 > 3) float myFloat = 40.0; boolean b = (boolean)99;
(true & true)
(4 & 5)
(int myInt = 0 > 3)
float myFloat = 40.0;
boolean b = (boolean)99;
repaint() update() paint() draw() show()
draw()
show()
TextField tf = new TextField(30);
This code is illegal, there is no such constructor for TextField Creates a TextField object than can hold 30 rows, but since it is not initialized to anything, it will always be empty Creates a TextField object that can hold 30 columns, but since it is not initialized to anything, it will always be empty Creates a TextField object that can hold 30 rows of text Creates a new TextField object that is 30 columns of text
TextField
Boolean b1 = new Boolean(true); Boolean b2 = new Boolean(true);
b1 == b2 b1.equals(b2) b1 & b2 b1 | b2 b1 && b2 b1 || b2
b1 == b2
b1.equals(b2)
b1 & b2
b1 | b2
b1 && b2
b1 || b2
Test
class Test { public static void main() { System.out.println("hello"); } }
The program does not compile because main() is not defined correctly. The program compiles but when you try to run the interpreter complains that it cannot find the main() method it needs to run The program compiles but you cannot run it because the class is not declared as public The program compiles and runs without an error but does not display anything in the standard output The program compiles and displays hello in the standard output when you run it
passes that event up the container hierarchy stops that event from being passed up the container hierarchy has no effect on whether the event is passed up the container hierarchy
You can directly free memory allocated by an object You can directly run the garbage collector whenever you want to The garbage collector informs your object when it is about to be garbage collected The garbage collector reclaims an object's memory as soon as it becomes a candidate for garbage collection The garbage collector runs in low-memory situations
&&
int long double boolean float
void main(String[] args) { } static public void main(String args[]) { } public static void main(String[] args) { } public static int main(String[] args) { } public static void main(String args[]) { }
void main(String[] args) { }
static public void main(String args[]) { }
public static void main(String[] args) { }
public static int main(String[] args) { }
int float char boolean Object
char
zero instanceof implements NULL sizeof goto
zero
instanceof
implements
NULL
sizeof
goto
s
t
String s = "Here's to you "; String t = s + "Mrs. "; String t += "Robinson.";
s = "Here's to you " t = "Here's to you Mrs. Robinson." s = "Here's to you Mrs. " t = "Here's to you Mrs. Robinson." s = "Here's to you Mrs. " t = "Mrs. Robinson." s = null t = "Here's to you Mrs. Robinson." s = null t = "Robinson."
s = "Here's to you "
t = "Here's to you Mrs. Robinson."
s = "Here's to you Mrs. "
t = "Mrs. Robinson."
s = null
t = "Robinson."
Object b1 = new Boolean(false); Object b2 = new Boolean(false); System.out.println(b1.equals(b2));
This code will not compile because you cannot assign a Boolean to an Object This code will not compile because you cannot test for equality of two Boolean values using equals() This code compiles and when it runs it displays the word true This code compiles and when it runs it displays the word false This code runs but throws NoSuchMethodException
equals()
String s = "Maybe "; s += " not";
s contains "Maybe not" at the end. This code produces a String object that becomes a candidate for garbage collection Only one String object is created This code produces an exception because a String object cannot be modified once it is created
"Maybe not"
trim()
Can remove all leading white space Can remove all trailing white space Can trim the String to a substring specified as a parameter Can trim the String to start and end indexes specified as parameters
start() runnable() run() init() main()
start()
runnable()
run()
- += >> & none of the above
-
+=
>>
&