True or False: There must be at least one public entity (class, enum, interface) in a file? (enter 'true' or 'false'). :: false ?? 30 Which array declaration is not legal? a)int[] ints = new int{3,5,7}; b)int ints[] = { 3,5,7 }; c)int[] ints [] = new int[3][]; d)int ints[] = new int[3]; :: a ?? 60 Given: enum Boats { SKIFF,CORACLE,BARGE } public class DoBoats { Boats boat; public static void main(String...args) { DoBoats db = new DoBoats(); db.boats = ___; System.out.println(db.boats); } } What must replace '___' if the output of the program is CORACLE? a)"CORACLE" b)Boats.CORACLE c)DoBoats.Boats.CORACLE d)db.Boats.CORACLE :: b ?? 60 Given: enum Boats { SKIFF(8), CORACLE(10), BARGE(20); Boats(int size) { this.size = size; } public int getSize() { return size; } } Invoke the getSize() method on SKIFF(complete with semi-colon). :: Boats.SKIFF.getSize(); ?? 60 Given: class A { enum Boats { SKIFF,CORACLE,BARGE } Boats boat; } class B { public static void main(String...args) { A a = new A(); a.boat = ___; } } What sets boat in the instance of A (a) legally? a)"SKIFF" b)a.Boats.SKIFF c)Boats.SKIFF d)A.Boats.SKIFF :: d ?? 60 Given: class A implements Progs { int a = b; public static void main(String...args) { System.out.println(b); } } What modifiers (access or otherwise) MUST b have? a)private,hidden b)default,final c)public,static,final d)does not compile :: c ?? 60 Enter an alphabetized, comma-separated list (with no spaces) of illegal non-access modifiers for method declarations in interfaces. (like one,two,three). :: final,native,static,strictfp,synchronized,transient,volatile ?? 60 What access modifiers can an interface have? a)default b)public c)public,private d)public,protected e)public,default :: e ?? 30 What is true about overriding interface methods in a class? a)This is only possible if the class extends the interface. b)The overriding version must use the same implementation code as the interface version. c)The access modifier must be public. d)The access can be public or default. e)The overriding method's access modifier is public by default, whether or not it is so declared. :: c ?? 60 Why won't this file compile? public enum Boats { SKIFF,CORACLE,BARGE } public class DoBoats { Boats boat; public static void main(String...args) { DoBoats db = new DoBoats(); db.boat = Boats.BARGE; System.out.println(db.boat); } } a)The argument to main is improperly formatted. b)The Boats enum is not accessible from within the static context. c)The compiler will not allow both the enum and the class to have public access modifiers. d)enums do not have toString() methods and so cannot be arguments to println. :: c ?? 60 Given: package com.icecream; import java.io.*; import java.util.*; class A { public void writeOrder(String[] order) { try { PrintWriter pw = new PrintWriter(new FileWriter("../ic/current.txt")); for (String field:order) pw.println(field); pw.close(); }catch(IOException ioe) { System.out.println(ioe.getMessage()); } } } public class B { static A a = new A(); public static void main(String...args) { ArrayList list = new ArrayList(); list.add("done_4_9"); String[] newone = { "strawberry","3","ups_ground" }; a.writeOrder(newone); System.out.println("Done."); } } Assuming that the relative path is valid, what is the result? a)Doesn't compile because of the <>'s in the ArrayList b)Compiles and executes as indicated. c)Doesn't compile because the second class also needs a java.util import. d)Doesn't compile because the first class listed must be public. :: b ?? 90 Enter the four access privilege levels in a comma-separated list, with no spaces, from most permissive to least permissive (ie one,two,three). :: public,protected,default,private ?? 60 What is the result of this code? public class Manager { private int codeDir = 5; public static void main(String...args) { Manager m = new Manager(); System.out.println("Doing process..."); m.doProcess(); } public void doProcess() { private int counter = 0; while (counter++ < 10) { codeDir /= 1; System.out.print(codeDir); } } a)There is a runtime exception. b)The code does not compile because division operations need to declare or handle arithmetic exceptions. c)The code compiles and prints nine 5's. d)The code does not compile because of some other reason. e)The code compiles and prints ten 5's. :: e ?? 90 Given: /java | --src | --classes | --alpha | | | --A.class | --beta | --B.class package alpha; class A { int x = 7; } ------- package beta; import alpha.*; public class B { public static void main(String...args) { System.out.println(new A().x); } } ...and the invocation java -cp /java/classes beta.B What is the result? a)Compile error--B cannot reference A. b)prints 7. c)Compile error--IllegalAccessError on x.. d)prints 0. :: a ?? 90 class CharTest { public static void main(String...args) { char c = 97; //97 is ascii code for 'a' System.out.println(c); } } What is the result of this code? a)Compilation error--println can't take a char as an argument. b)prints 'a'. c)Runtime exception--cast is required. d)prints 97. :: b ?? 60 Can the modifier 'volatile' be applied to methods? a)yes b)no :: b ?? 30 Which may use the static modifier? a)constructors b)init blocks c)classes d)method-local inner classes e)methods f)regular inner classes :: b,e,f ?? 60 public class DoIt { static final Object myObj = new Object() { String name = ""; }; public static void main(String...args) { myObj.name = "fred"; System.out.println(myObj.name); } } What is the result? a)prints "fred" b)Runtime exception c)Compilation error--bad inner class formulation d)Compilation error--can't modify final variable myObj after initialization. e)Compilation error--can't find symbol 'name'. :: e ?? 60 When must final vars be initialized? a)before use b)on the same line on which they are declared c)before the constructor runs d)none of the above :: c ?? 60 Which are static methods of Thread: (x,y,z--no spaces) a)join b)wait c)notifyAll d)sleep e)start f)yield :: d,f ?? 60 Enter the five flags used with the printf/format methods a)Z b)0 c)!! d)[ e), f)+ g)( h)* i)@ j)^ k)- :: b,e,f,g,k ?? 60 Can a Scanner be constructed in this manner? Scanner sc = new Scanner("../records/JoeMomma.rec"); a)yes b)no :: a ?? 30 package test; Given these 2 files: package test; public class A { int x = 7; public void f() { System.out.print(x); } } -------------------------- package quiz; import test.*; class B extends A { int x = 8; } public class C { public static void main(String...args) { B b = new B(); b.f(); A a = new B(); a.f(); } } What is the result of running C? a)Compiler error. Class B cannot redefine 'int x'. b)prints 88. c)prints 87. d)Runtime Exception. e)prints 77. :: e ?? 90 Given this file: package test; class CastA {} class CastB extends CastA {} class CastC extends CastA {} public class CastTest { public static void main(String[] args) { CastA ca = new CastA(); CastB cb = new CastB(); CastC cc = new CastC(); cb = (CastB)ca; //a cb = (CastB)cc; //b ca = (CastA)cc; //c <----CHOOSE a-e cb = (CastA)cc; //d cc = (CastC)cb; //e } } Which casts, labeled a-e, will compile? (enter x,y,z--no spaces) :: a,c ?? 90 Given: class A { } class B extends A { } public class Test { public static void main(String...args) { A a = new A(); A c = new B(); B b = new B(); } } And: b = ( )c; Enter the contents of the ()'s necessary to effect a down-cast. :: B ?? 60 Given: interface Meths { void f(); int g(); } abstract class MoveOn implements Meths { void runnit(int x); public int g() { System.out.print("g"); } public static boolean former(boolean b) { if (b) return !b; else return b; } } public class MoveIn extends MoveOn { ... Class MoveIn must... a)override runnit(). b)implement f() and override g() and former(). c)implement f() and runnit(). d)implement f() and g() and runnit() and override former(). e)MoveOn will inherit f(), g(), runnit() and former() but has no particular requirements with respect to these methods. :: c ?? 90 What is true about static methods? (x,y,z--no spaces) a)A static method may be overridden to be non-static. b)A static method has the same access to instance variables as non-static methods. c)A static method may be accessed using the dot operator on a reference to the class in which it is defined. d)A non-static method may be overridden to be static. e)A null reference of the same type as defines a static method can be used to invoke the static method. f)static methods may be overridden, but not overloaded. :: c,e ?? 60 What code fragments are associated with encapsulation? (x,y,z--no spaces) a)synchronized f(). b)transient int x = 7. c)public int getSize(). d)static init { . e)private String name; :: c,e ?? 60 What is true about loose coupling, high cohesion, and encapsulation? (x,y,z--no spaces) a)Encapsulation refers to placing critical code in a synchronized method. b)High cohesion is code which has numerous calls between classes, functionally linking the classes together. c)Loosely coupled code is characterized by proper encapsulation. d)High cohesion refers to the focus of operations in a class on one end or purpose. e)High cohesion refers to the brevity of class code. f)Classes with many 'has-a' relationship to other classes are considered tightly coupled. :: c,d,f ?? 90 An object that can pass an is-A test is considered polymorphic. True or false? (true/false) :: true ?? 30 What is the result of the following code? import java.util.*; class ACheck { Number f(String s) throws NumberFormatException { Integer i = Integer.parseInt(s); System.out.println("ACheck"); return i; } } public class BCheck extends ACheck { public Integer f(String s) { Integer i = null; i = Integer.parseInt(s); System.out.println("BCheck"); return i; } public static void main(String...args) { ACheck ac = new BCheck(); System.out.println(ac.f(args[0])); } } Invocation: java BCheck 3 a)Runtime Exception. b)Compile error--overriding method doesn't handle or declare exception. c)prints BCheck 3 d)Compile error--illegal return type. :: c ?? 120 Method a() in class Parent throws FileNotFoundError. Class Child extends Parent and overrides a(). Overriding a() throws IOException. Assuming all the other code is legal, will this compile? a)yes b)no :: b ?? 30 Can these two methods appear in the same class? public void f(int i) { this.i += i; } public void f(int i) { this.i += ++i; } a)yes b)no :: b ?? 30 Given: class A { void f(int x) { char f = 'f'; x+=f; System.out.print(x); } } Which are legal overrides? a)public void f(int z) { System.out.println(f); } b)void f(int x) { System.out.println(f); } c)void f(int x) { char f = 'f'; x+=f; System.out.print(x); } d)protected void f(int x) { char f = 'F'; x %= f; System.out.print(x); } e)private void f() { char f = 'f'; x+=f; System.out.print(x); } :: a,b,c,d ?? 60 What is the output? (x,y,z--no spaces) class A { int x = 7; static void doP() { System.out.println(x); } } public class B extends A { int x = 8; static void doP() { System.out.println(x); } public static void main(String...args) { A a = new B(); a.doP(); } } a)7. b)8. c)Runtime exception. d)Compile error--static methods may not be overridden. e)0. :: a ?? 60 What is the result of this code? (x,y,z--no spaces) public class DoCalc extends Calc { private float coEf = 0.71f; float calc1(int flanges) { float ship = flanges * coEf; return ship; } public static void main(String...args) { DoCalc dc = new DoCalc(); System.out.println("ship rating is " + dc.calc1(10)); } } class Calc { float coEf = 0.71f; double calc1(int flanges) { double ship = 1.0 * flanges * coEf; return ship; } } a)Runtime exception. b)prints "ship rating is [some float #]". c)prints "ship rating is [some double #]". d)Compile error--attempting to use incompatible return type. e)Compile error--unknown variable coEf. :: d ?? 90 Does this code compile? public class Paradox { int x; void g(boolean b) { if (b) x = 9; else x = 8; } public void g(boolean trueFalse) { if (!trueFalse) x = 9; else x = 10; } public static void main(String...args) { new Paradox().g(true); System.out.println("x is " + x); } } a)yes b)no :: b ?? 60 What is the result of this code? (x,y,z--no spaces) package test; class InherA { int x = 7; void m() { System.out.println(x); } } public class InhVars extends InherA { int x = 8; public static void main(String...args) { InhVars iv = new InhVars(); System.out.println(iv.x); iv.m(); } } a)Runtime exception. b)Compile error--duplicate variables. c)8 [\n] 8. d)7 [\n] 7. e)7 [\n] 8. f)8 [\n] 7. :: f ?? 90 Given: import java.util.*; import java.io.*; class Top { List readIt() { ArrayList lines = new ArrayList(); try { BufferedReader br = new BufferedReader(new FileReader("myfile.txt")); String line = ""; while ((line = br.readLine())!=null) lines.add(line); }catch(IOException ioe) { System.err.println(ioe.getMessage()); } return lines; } } public class ThrowEx extends Top { public static void main(String...args) throws IOException { ThrowEx te = new ThrowEx(); ArrayList fileLines = te.readIt(); } ArrayList readIt() throws IOException { ArrayList lines = new ArrayList(); BufferedReader br = new BufferedReader(new FileReader("myfile.txt")); String line = ""; while ((line = br.readLine())!=null) lines.add(line); return lines; } } What is the result? a)The code throws a FileNotFoundException because there is no path specified. b)Compile error because the overriding throws a checked exception that is not thrown by the overridden method. c)The code compiles without errors or exceptions. d)none of the above. :: b ?? 120 Given: class Weakicus { final int x; void g() { System.out.println("boo"); } Weakicus() { g(); } public static void main(String...args) { Weakicus wc = new Weakicus(); wc.x = 7; } } What is the outcome of this code? (x,y,z--no spaces) a)Compile error--illegal call to g() from constructor. b)Runs with no output because g() is not ready when the constructor runs. c)Compile error--x cannot be initialized after the constructor has run. d)Compiles, runs, and prints boo e)None of the above. :: c ?? 90 Enter the one character that may begin a valid Java identifier besides a-z, A-Z and $? (Enter one character) :: _ ?? 30 Enter an alphabetical, comma-separated list of all access levels available to defined constructors. (alpha,beta,etc) :: default,private,protected,public ?? 60 If a class with a main method is invoked with java, does its constructor run? (a or b) a)yes b)no :: b ?? 30 Given this fragment: MyClass() { System.out.println("Instantiating."); } What line of code (complete with semicolon) does the compiler insert in the fragment above? (complete line of code;) :: super(); ?? 60 Abstract classes can have constructors; Abstract class constructors can be invoked and run. (booleanVal,booleanVal) :: true,true ?? 60 When is explicit member variable initialization code executed? (x,y,z--no spaces) a)When the class is loaded. b)When the class's main method runs. c)After a class constructor runs. d)After a class constructor begins to run, but before it completes. e)Whenever they are first referenced in method code. :: d ?? 60 Given: class Ball { int diameter; int weight; Ball(int d,int w) { diameter = d; weight = w; } } class SportsBall extends Ball { String sport; String material; } class BaseBall extends SportsBall { String core; float cost; BaseBall(String core,float cost) { this.core = core; this.cost = cost; } BaseBall() { } } public class DoBall { public static void main(String...args) { BaseBall bb = new BaseBall(); bb.sport = "baseball"; bb.material = "leather"; System.out.println("Sportsball ready to be made baseball."); } } What is the result of this code? (x,y,z--no spaces) a)Compile error--"DoBall" does not have access to other classes. b)Runtime exception. c)Compiles and prints message. d)Compile error--no default constructor exists for class 'Ball'. :: d ?? 120 Given: public class Bau { int x; Bau(int x) { this.x = x; System.out.print("print? "); } Bau() { System.out.print("Does this "); } public static void main(String...args) { Bau b = new Bau(7); b.this(); } } What is the result of this code? a)Compiles and prints "7Does this print?" b)Compiles and prints "Does this print?"; c)Runtime exception. d)Compile error--'b.this()' not a statement. :: d ?? 90 Given: package test; public class Innitted { static boolean status; int x; Innitted(int count) { this.x = count; System.out.print("in const: x is " + x); } public static void main(String...args) { System.out.print("in main:"); Innitted inn = new Innitted(7); } static { status = true; System.out.print("in block:"); } } What is the output of this program? a)Compile error. b)Runtime exception. c)"in block:in const: x is 7in main:". d)"in block:in main:in const: x is 0". e)"in block:in main:in const: x is 7". :: e ?? 90 Arrange the following class components in the order in which they run. Assume the class has a main method whose first line instantiates the class. (x,y,z--no spaces) i. static init blocks ii. instance init blocks iii. explicit member variable initialization iv. main method //assume there is one v. explicit static variable initialization vi. constructor a)v,i,iv,vi,ii,iii b)v,i,iv,vi,iii,ii c)iv,vi,i,ii,v,iii d)i,ii,v,iii,iv,vi e)Depends on the circumstances :: a ?? 90 What is true about init blocks? (x,y,z--no spaces) a)They can be invoked at any time, from any method code. b)They run once, when the constructor completes. c)If there is more than one, the order of execution is jvm dependent. d)If an exception occurs in either an instance or a static init block, an ExceptionInInitializerError is thrown. e)static init blocks run once, after static variables are initialized, when the class is loaded. f)Instance init blocks run after the constructor's call to super(), before the constructor completes. g)Both varieties of init blocks must appear after member declarations, but before any method code. :: e,f ?? 90 Which statement best describes constructor chaining? (one option only) a)The first constructor invoked invokes an overloaded constructor of the class using 'this()' syntax, and so on, until all of the constructors of the class have run. b)A suite of related classes in a given package are instantiated via a series of chained constructor calls. The first constructor to run invokes the keyword 'chain' which causes implicit calls to the next constructor in the package which also includes the 'chain' keyword. This process continues until all of the 'chain'ed constructors have been called, then execution continues back down the stack until the initial class constructor completes. c)'Constructor chaining' is not a Java concept. d)When a constructor runs, it completes any calls to overloaded constructors and then, either explicitly or implicitly, a constructor of its super class is called. This process continues in a chain until all superclass constructors have been called, then execution continues back down the stack until the initial class constructor completes. e)None of the above. :: d ?? 90 Given these array declarations: int[] x; boolean status[]; short[][] results; char[] z = new char[4]; Which are legal array assignments? (x,y,z--no spaces) a)x[0] = new Short((short)7); b)status = new Boolean[3]; c)x = new long[5]; d)x = new int[3]; e)results = { {1,2,3},{4,5,6},{7,8,9} }; f)results = new short[][]; g)z[0] = 38; h)z[1] = (byte)7; :: b,d,e,g,h ?? 120 Given: import java.util.*; public class OLoads { public static void main(String...args) { OLoads ol = new OLoads(); ol.a((byte)7); ol.b(new Integer(7)); ol.c(7L); ol.d((short)8); ol.e(); ol.f(3); } void a(byte bite) { System.out.print("a-1:"); } void a(Byte Bite) { System.out.print("a-2:"); } void b(float fl) { System.out.print("b-1:"); } void b(Integer i) { System.out.print("b-2:"); } void c(float flote) { System.out.print("c-1:"); } void c(double dub) { System.out.print("c-2:"); } void d(Object o) { System.out.print("d-1:"); } void d(Integer i) { System.out.print("d-2:"); } void e(String...s) { System.out.print("e-1:"); } void e() { System.out.print("e-2:"); } void f(Float Fl) { System.out.print("f-1:"); } void f(float...phlote) { System.out.print("f-2:"); } } What is the output? (Select one option) a)a-1:b-1:c-2:d-1:e-1:f-1 b)a-2:b-1:c-1:d-1:e-2:f-2 c)a-2:b-2:c-2:d-1:e-1:f-2 d)a-1:b-1:c-2:d-1:e-2:f-2 e)a-1:b-2:c-2:d-1:e-2:f-2 :: e ?? 180 Given this code fragment: Integer i1 = 125; Integer i2 = 125; Integer i3 = new Integer(125); Integer i4 = new Integer(125); Integer i5 = 128; Integer i6 = 128; System.out.println(""+i1==i2 + " " + i3==i4 + " " + i5==i6); What is printed? (Select one option) a)true true true b)true true false c)false true true d)true false false e)false false false f)false true false :: d ?? 90 Given the following code fragment: Short s1 = 3; Short s2 = 3; Short s3 = new Short((short)-129); Short s4 = new Short((short)-129); Short s5 = -129; Short s6 = -129; System.out.println(s1.equals(s2) + " " + s3==s4 + " " + s5==s6); What is printed? (Select one option) a)true true false b)false false false c)true true true d)false true false e)true false false :: e ?? 90 Does this code compile: (Select 'a' or 'b') Character Ch = new Character(64); a)yes b)no :: b ?? 30 What is the result? (Select one option) Integer Int = 77; Short Sh = 3; System.out.println(sh+Int); a)Compile error--invalid arguments to println b)Compile error--arguments must be derefrenced before they can be used as operands in an arithmetic statement. c)Runtime exception. d)74 e)80 :: e ?? 30 Given: import java.util.*; class TorF { public static void main(String...args) { Boolean b = new Boolean(args[0]); //#1 if (b) System.out.print("Yohoho"); else System.out.print("Yeehee"); //#2 } } and the invocation 'java TorF TRUE' What is the output? (Select one option) a)Compile error--line # 1 must be in try/catch blocks b)"Yohoho" c)Compile error--line # 2 lacks proper backets d)"Yeehee" e)"YohohoYeehee" :: b ?? 60 Which are valid Wrapper operations? (x,y,z--no spaces) a)Integer x = new Integer(7).valueOf(8); b)Character ch = new Character("q"); c)Character ch = new Character(64); d)Character ch = new Character((char)64); e)System.out.println(Short.toBinaryString(64)); f)System.out.println(Boolean.toString(false).toUpperCase()); :: a,d,f ?? 60 Given: System.out.println(Integer.__); Type exactly what should go in the blank to produce the output "1000". :: toBinaryString(8) ?? 60 Given: public class ArTest { String[] ss; public static void main(String...args) { ArTest at = new ArTest(); String[] strings; System.out.println(at.ss + " and " + strings); } } What is the output? (Select one option) a)Compile error--variable 'at.ss' might not have been initialized. b)"null and null". c)Compile error--variable 'strings' might not have been initialized. d)Compiles but no output. e)Compiles but only output is a new line. :: c ?? 60 When do instance variables get their default, as opposed to their explicit, values? (Select one option) a)When the class is loaded. b)When the constructor completes. c)When the (explicit or default) call to super() returns, unless the object is of *class* Object. d)After the class is loaded but before the class constructor runs. e)None of the above. :: d ?? 60 Given: package test; class Fest { Fest() { printThree(); } void printThree() { System.out.println("three"); } } class Super extends Fest { int three = (int)Math.PI; // That is, 3 public static void main(String[] args) { Super s = new Super(); s.printThree(); } void printThree() { System.out.println(three); } } What is the output? (Select one option) a)three three b)three 3 c)Compile error--illegal method call in constructor d)0 3 e)None of the above. :: d ?? 90 Given: package test; public class PbyVal { public static void main(String...args) { PbyVal pv = new PbyVal(); int x = 7; boolean b = true; pv.a(x); pv.bee(b); PbyVal.myOb mo = pv.new myOb(); pv.c(mo); System.out.print("After method calls: x=="+x+";b=="+b+";"); System.out.println(mo.name.equals("ichi-ban")); } class myOb { int x = 7; String name = "ichi-ban"; } void a(int x) { x=227; } void bee(boolean b) { b = false; } void c(myOb mo) { mo = new myOb(); } } What is the output? (Select one option) a)"x==227;b==true;true" b)"x==227;b==false;false" c)"x==7;b==true;true" d)"x==7;b==false;true" e)None of the above :: c ?? 120 True or false: primitive wrapper objects of different types are never 'equal'[()]? ('true' for 'false') :: true ?? 30 What is the result of the following code fragment: (Select one option) 1) int[] ints; 2) Integer[] iWraps = { (new Integer(1)),(new Integer(2)) }; 3) ints = iWraps; a)Line 2 doesn't compile because the array is incorrectly initialized. b)ints is initialized with an array of Integer wrappers. c)Line 1 doesn't compile because 'ints' is a keyword (reserved word). d)Line 3 doesn't compile because the 'ints' reference cannot hold the object pointed to by iWraps. e)iWrap 'unboxes' and assigns itself as an array of ints to 'ints'. :: d ?? 60 Given: public class BoolArr { public static void main(String...args) { Boolean[] tfs = new Boolean[3]; System.out.println(tfs[1]); } } Enter the output not in quotes. :: null ?? 60 How many unique versions of 'x' are in the following code? public class Scopes { int x = 7; { int x = 8; } Scopes() { x = 10; } public static void main(String...args) { int x = 9; System.out.println(x); Scopes sc = new Scopes(); sc.g(); } void g() { int x = 11; for (x = 0;x<11;x++) { //do something } } } :: 4 ?? 60 What happens in the following code? (Select one option) Dog d = new Dog(); -->Dog c = d;<-- a)A new Dog object is created and assigned to reference variable c. b)The Dog object that was in d is transferred into the new Dog reference variable c, leaving d null. c)Dog reference variable d is duplicated in Dog reference variable c, so that d and c are exactly alike. d)A null Dog reference variable is tested for equality with another Dog reference variable. e)None of the above. :: c ?? 60 What is true about Java integers? (x,y,z--no spaces) a)They are referred to in Java exclusively via the keyword 'int'. b)They can be expressed as simple numerals or as hexadecimals or octals. c)0x771 is an integer. d)They can be represented in binary form if a 'b' prepends the number: 'b0011'. e)'c' is an integer. f)new Integer(3).intValue() is an integer. :: b,c,e,f ?? 90 What is the result of this code? (Select one option) char c = -1; a)c is assigned -1, which corresponds to an ascii character. b)c is assigned the absolute value of any integer and thus is set to 1, which corresponds to an ascii character. c)Compile error--an explicit cast to char is required to make this assignment because the integer is a negative value. d)Compile error--char is an unsigned type and cannot take negative numbers. e)Compile error: -1 has no corresponding ascii character and thus the assignment fails. :: c ?? 60 One way to attempt to get the jvm to do garbage collection is to call System.gc(). What is the other? Enter the code below, in one statement without making an assignment. End with a semi- colon. :: Runtime.getRuntime().gc(); ?? 90 If the code in finalize() revitalizes an object by establishing a reference to it in the outside code, will finalize() run again if the object once again is subject to gc? (Select one option) a)yes b)no c)This is jvm dependant. d)None of the above. :: b ?? 30 What is true about Java garbage collection? (x,y,z--no spaces) a)It applies to all objects on the stack. b)It will void all objects which do not have references to them and will not void objects in an 'islands of isolation' relationship. c)It runs only once in the life of an object, unless the object's finalize() method re-establishes a reachable reference in the program code. d)Objects declared in methods nevertheless are on the heap and must be explicitly un-referenced to become eligable for gc. e)It runs much like the thread scheduler--according to its own priorities, and cannot thus be reliably invoked at a specific time. f)None of these statements are correct. :: e ?? 90 Which of the following assignments compile? (x,y,z--no spaces) a)char c = -29; b)byte b = -29; c)long l = -29; d)char c = 29; e)short s = -29; f)int i = -29f; :: b,c,d,e ?? 60 Is the following method code legal? (Select one option) byte b = 1; b+=7; a)Yes, and the result becomes an int. b)Yes, the result becomes a byte. c)No, due to possible loss of precision. d)No, compound operators require that the operand be of a matching type. :: b ?? 30 Given: int x = 7; int y = x; ++x; System.out.println(y); What prints? (Select one option) a)14 b)7 c)8 d)1 e)'x' :: b ?? 60 Does the following code compile? (Select one option) int i = 7 * 2.1; a)Yes, but the result truncates the decimal information. b)Yes, and i is converted to a floating point type. c)Yes because 2.1 is a float by default, the same size as int. d)No, the floating point number must have some kind of designator signalling whether it is a float or a double. e)No, the product of the operands is a double, so a cast would be required. :: e ?? 30 Which of these assignments are legal? (x,y,z--no spaces) a)char c = (char)-256; b)byte b = c; c)int x = 3.14; d)short = 199; e)float f = 3.14; :: a,d ?? 60 Given: public class DoStuff { static Object o = new Object(); static int x = 7; public static void main(String...args) { Object p = new Object(); if ((x=8)==8) { //line 1 System.out.println(p.equals(o)); //line 2 } } } What is the result of the code? (Select one option) a)Compile error, line 1: not a statement. b)Runtime exception. c)Compile error, line 2: equals() undefined in Object. d)The program compiles, but there is no output. e)The program compiles and prints 'true'. f)The program compiles and prints 'false'. :: f ?? 60 Which of the following are proper uses of the 'instanceof' operator? (x,y,z--no spaces) a)System.out.println(Number instanceof Object); b)Integer Int = new Integer(7); String s = "yazzi"; System.out.println(Int instanceof String); c)Integer Int = new Integer(7); System.out.println(Int instanceof Number); d)System.out.println(String instanceof CharSequence); e)String s = "yazzi"; System.out.println(s instanceof CharSequence); f)Integer Int = new Integer(7); Double Dub = new Double(3.14); System.out.println(Int instanceof Dub); :: b,c,e ?? 60 Given: public class Zippy { public static void main(String[] args) { int x = 7; int y = 9; System.out.println("The answer is " + x + y); System.out.println(x + y); System.out.println("The answer is " + (x + y)); } } What is the output? (Select one option) a)"The answer is 79" "16" "The answer is (16)". b)"The answer is 16" "79" "The answer is (79)". c)"The answer is xy" "xy" "The answer is 16". d)Compile error--no such method System.println(String,int); e)"The answer is 79" "16" "The answer is (xy)". :: a ?? 60 Given: public class DoOps { public static void main(String[] args) { int x = 7; System.out.println(7 % -5); System.out.println(-7 % 0); System.out.println(8 % -++x); } } What is the output? (Select one option) a) 2 0 -1 b) 2 -7 -2 c)-2 -7 Runtime exception. d)-2 0 0 e) 2 Runtime exception. :: e ?? 60 Given: public class Compit { public static void main(String[] args) { char c = 'c'; System.out.println(c > 100); //line 1 } } What is the basis for the comparison in line 1? (Select one option) a)The comparison is based on the relative position of 'c' and '100' in the ascii character set. b)The comparison is based on an entity hierarchy--primitive variables are considered greater than literals, and c is a variable, 100 a literal. c)When a primitive reference is compared to a literal value, the address of the reference in memory is used as the value for the reference. d)When a char is used in a numerical comparison, the char's unicode value is used. :: d ?? 60 Given: public class Evall { public static void main(String[] args) { int x = 7; boolean b = false; if ((++x>7) | (x--==6)) // line 1 System.out.println(--x>6&&!b?--x:x++); // line 2 } } What is the result? (Select one option) a)5 b)6 c)7 d)Compile error--line 1 e)Compile error--line 2 :: b ?? 90 Given: public class DoLoops { public static void main(String[] args) { int x = 7; int y = 8; for (x=0;x<=y;x++) { //line 1 System.out.print(". "); } int[] ints = new int[]{ 2,3,4 }; //line 2 System.out.println(""); for (x:ints) //line 3 System.out.println("* "); } } What is the result of this code? (Select one option) a)Compile error at line 1--x must be declared within the loop statement. b)Compile error at line 2--illegal array initialization. c)Compile error at line 3--x must be declared within the loop statement. d)Other compile error. e)The code compiles and prints periods horizontally and asterix's vertically. :: c ?? 60 Given: public class DoLoops1 { public static void main(String[] args) { int y = 5; while (y++<10) { int x = y; x++; --x; ++x; } System.out.println("Ending x value: " + x); } } What is the output? (Select one option) a)"Ending x value: 11". b)"Ending x value: 10". c)Compile error--variable y unknown within while loop. d)Compile error--variable x unknown outside while loop. e)None of the above. :: d ?? 30 What is true about Java loops? (x,y,z--no spaces) a)The expression in do and while loops must evaluate to something (ie not null) b)Any variables used in the 'boolean expression' or 'iteration expression' portion of a basic for-loop must be declared in the 'declaration expression' portion. c)Enhanced for-loops' shorthand syntax makes them an easier, simpler alternative to all basic for-loops. d)Regular for-loops can omit everything except semi-colons from their expressions and still run effectively. e)while-loops are guaranteed to execute their boolean expressions at least once, and do-loops are also guaranteed to execute their code blocks at least once. :: d,e ?? 60 Given: public class DoLoops2 { public static void main(String[] args) { int x = 0; boolean b = true; do { x++; System.out.print(". "); cujo: do { System.out.print("* "); do { if (b) break cujo; System.out.print("^ "); } while (x < 3); } while (x < 4); } while (x < 5); } } What is the output? (Select one option) a)Compile error--'cujo:' is not a statement. b)". * ^ . * ^ . * ^ . * ^ . * ^" . c)". * . * . * . * . *" d)Compile error--'cujo:' isn't on the right line. e)". * . . . ." . :: c ?? 90 Given: import java.util.*; public class Switchit { public static void main(String...args) { final int choice; int input = 0; try { input = Integer.parseInt(args[0]); }catch(NumberFormatException nfe) { System.err.println("Bad number: " + nfe.getMessage()); } choice = input; switch (input) { case choice: System.out.print("one"); //line 1 case (int)0.1: System.out.print("two"); break; //line 2 case 3: System.out.print("three"); //line 3 default: System.out.print("Bad data"); break; //line 4 } } } Invocation: java Switchit 3 What is the result of this code? (Select one option) a)"one". b)Compile error-- line 1 lacks a 'break' statement. c)"onetwo". d)Compile error-- line 2 has illegal case constant. e)Compile error-- line 1 has illegal case constant. f)None of the above. :: e ?? 90 Given: public class Switchit { public static void main(String...args) { short shoart = 124; byte bite = 121; switch (bite) { case 1: System.out.println("one"); break; case 127: System.out.println("byte"); break; case 2: System.out.println("two"); break; case shoart: System.out.println("short"); break; default: { break; } } } } What is the result of this code? a)The code compiles but there is no output. b)Compile error--illegal switch expression. c)Compile error--default statement improperly formed. d)Compile error--loss of precision from short to byte :: d ?? 60 Enter one word that describes the kind of statement which must appear within the parenthesis: if (?) { (Enter one word) :: boolean ?? 30 Which are common runtime exceptions? (x,y,z--no spaces) a)EndOfFileException b)ArrayIndexOutOfBoundsException c)ClassFormatException d)ArrayCastingException e)IllegalStateException f)NullPointerException g)FileNotFoundException h)ClassCastException :: b,e,f,h ?? 60 Given the file: /aubrey/java/classes/test/DoAssertion.class, containing: package test; public class DoAssertion { public static void main(String[] args) { int x = 7; assert (x==7): "x isn't 7"; System.out.println("Done."); } } and the invocation from a remote directory: java -cp /aubrey/java/classes DoAssertion What is the result? (Choose one answer) a)Prints "Done." b)Throws AssertionError, printing the stack trace and "x isn't 7". c)Prints "x isn't 7". d)Throws NoClassDefFoundError. :: d ?? 90 Given: package test; public class Oops { public static void main(String[] args) { int x = 7; while (x < 10) { x %=3; } System.out.println("Resulting x value: " + x); } } What is likely to result here? a)'x' will have a value of 1. b)Compile error-- '%=' invalid operator in this context. c)'x' will have a vlue of 7. d)A runtime exception will be thrown. e)A StackOverflowError will be thrown. :: e ?? 90 Which common runtime exceptions and errors are thrown by the jvm as opposed to programmatically? (x,y,z--no spaces) a)AssertionError b)ArrayIndexOutOfBoundsException c)IllegalStateException d)ExceptionInInitializerError e)NumberFormatException f)StackOverflowError g)NoClassDefFoundError h)IllegalArgumentException :: b,d,f,g ?? 90 Given this code fragment: public class BadInit { static x; static { x = 7; x /= 0; System.out.println(x); } ... Type the name of the direct subclass of Throwable that will result from this code, with appropriate CamelCase treatment: :: ExceptionInInitializerError ?? 60 Given: public class AssertIt { public static void main(String[] args) { int x = 7; int[] xs = new int[3]; xs[0] = 1; xs[1] = x; xs[2] = 2; assert (xs[2]==7): "x isn't 7!"; //line a System.out.println("x must be 7."); x/=0; //line b System.out.println(xs[2]); //line c } } Why isn't main() required to handle or declare the potential Throwables at the labeled lines in the code above? (Choose one answer) a)AssertionError and ArithmeticException are not the type of subclasses of Throwable that require handling or declaring. b)ArrayIndexOutOfBoundsException is a runtime exception and runtime exceptions do not need to be handled or declared. c)main() actually must handle or declare the Throwables at lines a and b. d)main() actually must handle or declare the Throwable at line c. e)NumberFormatException is a runtime exception and runtime exceptions do not need to be handled or declared. f)There are no potential or imminent Throwables that would result from the code above. :: a ?? 90 Given: public class CatchIt { public static void main(String[] args) { CatchIt ci = new CatchIt(); ci.f(args[0]); } void f(String arg) { try { int x = Integer.parseInt(arg); }catch(NumberFormatException nfe) { throw nfe; //line a } catch(IllegalArgumentException iae) //line b { System.err.print("oops."); } finally { System.out.print("Done with input."); } } } Invocation (though the code might not compile): java CatchIt three What is the result? (Choose one answer) a)Compile error--line a: can't throw and exception from a catch block b)Prints "Done with input" then a stack trace indicating an uncaught NumberFormatException. c)Prints "oops.Done with input." then exits. d)Prints "Done with input." then exits. e)Compile error--line b: can't immediately follow a NumberFormatException catch block with an IllegalInputException catch block. :: b ?? 90 Given: public class Thrown { void f() throws IndexOutOfBoundsException { char chars[] = new char[2]; chars[1] = '1'; chars[2] = '2'; } public static void main(String[] args) { Thrown t = new Thrown(); t.f(); System.out.println("Done."); } } True or False: main must "handle or declare" f()'s exception? (enter 'true' or 'false') :: false ?? 60 Given: public class BadCode { static void f(String input) { try { input.toUpperCase(); int x = Integer.parseInt(input); x/=0; }catch(Exception e) { System.err.println("Exception caught."); } catch(NumberFormatException nfe) { System.err.println("Format exception caught."); } } public static void main(String[] args) { f(args[0]); g(); } static void g() { try { int y = 7/0; }catch(ArithmeticException ae) { System.err.println(ae.getMessage()); } System.out.println("I know an exception will be thrown."); } } Invocation: java BadCode three What is true about the code? (x,y,z--no spaces) a)It will compile but will throw exceptions at runtime. b)There are no errors in methods f() or g(). c)There are no erros in method g(). d)f() will throw an ArithmeticException. e)f() will print "Format exception caught.". f)f() has one compile-time error. :: c,f ?? 120 Given: import java.io.*; public class Propagate { static BufferedReader br; void a() { b(); } void b() { c(); } void c() throws FileNotFoundException { br = new BufferedReader(new FileReader("")); } public static void main(String[] args) { Propagate p = new Propagate(); p.a(); System.out.println("Done."); } } Which method has an error due to failure to handle or declare? (Choose one answer) a)a() b)b() c)c() d)main() e)There are no errors--the code compiles. :: b ?? 90 Given: public class PrintF { public static void main(String[] args) { int x = 7; System.out.printf("%-d is the var.",x); } } What is the result? (Choose one answer) a)prints "7 is the var.". b)prints "-7 is the var.". c)prints "6 is the var.". d)prints "(7) is the var.". e)Throws MissingFormatWidthException. f)Compile error--illegal flag '-'. :: e ?? 60 Given the code fragment: int x = 7; System.out.printf("____ is the var.",x); Enter exactly what should go in the blank to cause the program output to be '+007 is the var.'. :: %+04d ?? 60 Given: public class Flange { public static void main(String[] args) { System.out.printf("%2$b or %1$b","FALSE",false); } } Enter the output of the program exactly as it would appear. :: false or true ?? 30 Given: public class Olympics { public static void main(String[] args) { System.out.printf("%6.2f%% were in favor of the olympics.\n",66.3124); } } What is the output? (Choose one answer) a)"66.3124% were in favor of the olympics.". b)"66.2% were in favor of the olympics.". c)"6.2% were in favor of the olympics.". d)" 66.31% were in favor of the olympics.". e)" 66.31% were in favor of the olympics.". f)Runtime exception--unknown conversion character '%'. :: e ?? 90 Given the code fragments: String[] parts; String source = "or things to be seized.||No person shall be held"; parts = ___________; Complete the code so that the string is tokenized according to an '||' delimiter. Omit the semicolon which is provided. :: source.split("||") ?? 60 Enter the regex symbol denoting "One or more" of the entity that preceeds it: :: + ?? 30 Enter the regex symbol denoting "Zero or 1" of the entity that preceeds it: :: ? ?? 30 How would you make 0[xX][a-fA-F0-9] match to any hexidecimal representation? (Choose one answer) a)Use the '*' metacharacter at the end of the pattern. b)Put some more '[a-fA-F0-9]' bracket on the end. c)Use the '.' metacharacter at the end of the pattern. d)Enclose the second brackets in paranthesis and then add a '*' metacharacter. e)Find out how many digits the hex numbers to be matched will be, and add that many of the [a-fA-F0-9] brackets. :: d ?? 90 Given: import java.util.*; public class PrintCal { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println(cal); } } What is the output? (Choose one answer) a)A formatted string containing date and time information. b)An odd series of characters suggesting that Calendar does not override the toString() method. c)A comma-separated list of constants and field name/value pairs defined by Calendar that is more than ten lines long. d)A formatted calendar for the current month with the current day in bold type. e)None of the above. :: c ?? 60 Enter the package containing the DateFormat class (do not add a semi-colon) :: java.text ?? 30 Which classes are abstract and use factory methods to create a usable instance? (x,y,z--no spaces) a)Date b)Calendar c)DateFormat d)NumberFormat e)Locale :: b,c,d ?? 30 True or false: DateFormat objects format strings that always include time information as well as date information. (true/false) :: false ?? 30 What is true about the DateFormat class formats? (x,y,z--no spaces) a)'May 13, 2009' is an example of the DateFormat.LONG format. b)'May 13, 2009' is an example of the format returned by the getInstance() factory method of DateFormat. c)'5/13/09' is an example of the DateFormat.MEDIUM format. d)'May 13, 2009' could be an example of both the Dateformat.MEDIUM and the DateFormat.LONG formats. e)'Thursday, May 13, 2009' is an example of the DateFormat.FULL format. f)'Thursday, May 13, 2009' is not representative of any of the formats available via the DateFormat class. :: a,d,e ?? 60 Given: import java.text.*; import java.util.*; public class Deights { static String date = "June 24, 2009"; static Date d; public static void main(String[] args) { DateFormat df = DateFormat.getDateInstance(DateFormat.FULL); try { d = df.parse(date); }catch(NumberFormatException nfe) { System.out.println("Parse error."); } System.out.println(d); } } What is the output? a)"June 24, 2009". b)Compile error--unknown symbol 'getDateInstance(integer)'. c)Runtime exception--'IllegalArgumentException' not handled by try- catch block. d)"Parse error. Wed Jun 24 00:00:00 CDT 2009". e)"Parse error. June 24, 2009". f)"Parse error. null". :: f ?? 90 Given this code fragment: DateFormat df = new DateFormat.getDateInstance(____________); Enter the code that must go in the blank to create a DateFormat object of the LONG format and for the locale US: :: DateFormat.LONG,Locale.US ?? 60 True or false: you can change the locale of a DateFormat object after it has been created? (true/false) :: false ?? 30 Enter the package that contains the Locale class: :: java.util ?? 30 Given that the ISO country codes for the United States, Germany, and Italy are US,DE, and IT respectively, and that 'it' is the ISO language code for italian, which code compiles? (x,y,z--no spaces) a)Locale usLoc = Locale.getInstance("US"); b)Locale usLoc = new Locale("US"); c)Locale itLoc = new Locale("it"); d)Locale itLoc = new Locale("it","IT"); e)Locale deLoc = Locale.DE; :: b,c,d,e ?? 60 Which are methods of Locale? (x,y,z--no spaces) a)getLang(). b)returnLang(). c)getDisplayCountry(Locale loc). d)getDisplayCountry(String isoCode). e)getDisplayLanguage(). :: c,e ?? 60 Enter the package that contains the NumberFormat class: :: java.text ?? 30 Given: import java.util.*; import java.text.*; public class NumberStuff { public static void main(String[] args) { NumberFormat nf = NumberFormat.getInstance(); float flote = 2.1f; nf.setParseIntegerOnly(true); System.out.println(nf.format(flote)); try { __________ Int = nf.parse(nf.format(flote)); System.out.println(Int); }catch(ParseException pe) { System.err.println("Bad parse."); } } } What can go in the blank besides Object to allow this code to compile and print 2.1 2 :: Number ?? 60 Given the code fragment: float bill = 212.33f; NumberFormat nf = NumberFormat.getCurrencyInstance(______); System.out.println(nf.format(bill)); What could go in the blank to print $212.33 (x,y,z--no spaces) a)Nothing. b)bill. c)Locale.US. d)"$" e)None of the above :: a,c ?? 60 Given the fragment: double widgets = 32.1273; NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); System.out.println(nf.format(widgets)); What prints? a)32.127 b)32.1243 c)Compile error--uknown symbol setMaximumFractionDigits(int) d)32 e)32.12 :: a ?? 60 Given: import java.io.*; class Wodget implements Serializable { String name; int weight; transient int partNum; } public class StoreIt { public static void main(String[] args) { Wodget w = new Wodget(); Wodget w2; w.name = "o-flange"; w.weight = 32; w.partNum = 211003; try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(w.name)); oos.writeObject(w); oos.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(w.name)); w2 = (Wodget)ois.readObject(); System.out.println(w2.name + " weighs " + w2.weight); System.out.println(w2.name + " has a part number of " + w2.partNum); ois.close(); }catch(Exception ioe) { System.err.println("IO exception."); } } } If the output of this code is o-flange weighs 32 o-flange has a part number of 0. What changes would allow partNum to be accurately represented in the print statement? (and in the w2 object) (Choose one option) a)StoreIt must implement writeObject() to write the transient variable 'partNum' to memory, and it must implement readObject() to read it back from memory. 'writeObject()' and 'readObject()' must contain calls to 'defaultWriteObject()' and 'defaultReadObject()' respectively. b)StoreIt must implement writeObject() and readObject() and it must also manually write the original value of partNum to the reconstituted object. It must obtain this value by some means devised by the programmer. c)Wodget must implement 'SerialExtended' (which extends Serializable) to gain the capacity to serialize and retrieve transient variables. d)Wodget must implement writeObject() to write the transient variable 'partNum' to memory, and it must implement readObject() to read it back from memory. 'writeObject()' and 'readObject()' must contain calls to 'defaultWriteObject()' and 'defaultReadObject()' respectively. e)There is no way to serialize a transient field. :: d ?? 180 Class "Cog" implements Serializable and overrides writeObject() and readObject() in order to handle a transient int field and a transient String field. What is true about the successful implementation of these methods? (x,y,z--no spaces) a)writeObject() must write these data to the file in the same order in which they are declared in "Cog." b)The int is written to the file using the 'writeInt()' method, and the String is written to the file using the 'writeString()' method. c)readObject() must read the specially-written fields back in the same order in which they were written. d)writeObject() must call writeDefaultObject() *before* it writes any additional data to the file. e)readObject() must call readDefaultObject() to serialize non-transient fields normally *before* it reads additional fields from the file. f)The call to writeObject must either be in a try/catch block (IOException), or IOException must be declared in method which calls writeObject. :: b,c,e,f ?? 120 Given: import java.io.*; class Soofi { int z = 8; } class Thing { protected int x = 7; } class Thingy extends Thing implements Serializable { int y = 8; Soofi sf = new Soofi(); } public class ObjGraph { public static void main(String[] args) { Thingy t1 = new Thingy(); t1.x = 9; Thingy t2; try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("t1")); oos.writeObject(t1); oos.close(); }catch(Exception e) { System.err.println("Serialization error."); } try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("t1")); t2 = (Thingy)ois.readObject(); ois.close(); System.out.println("t2.x is " + t2.x); }catch(Exception e) { System.err.println("Serialization error."); } } } What is true about this class? (x,y,z--no spaces) a)The file will compile and print 9 without any exceptions. b)Compile error--Soofi doesn't implement Serializable and therefore cannot be serialized as a field of Thingy. c)The file will compile and print 7 with one exception, causing "Serialization error" to print to output. d)The file will compile and print 0 with one exception, causing "Serialization error" to print to output. e)None of the above. :: c ?? 240 Given: File file = new File("myFile"); Which is a correct implementation of a File class method? (x,y,z--no spaces) a)File file2 = new File("fileTwo"); file.renameTo(file2); b)file.renameTo("fileTwo"); c)if (file.exists()) System.out.println("Exists."); d)file.createFile(); e)String[] files = file.list(); f)file.mkDir(); :: a,c,e,f ?? 60 Assuming that '/myFile' does not exist on the file system, and Given: import java.io.*; public class MakeIt { public static void main(String[] args) { File file = new File("/myFile"); } } What is true? (x,y,z--no spaces) a)There will be a runtime exception after the invocation of the program. b)The code could not have compiled because the file creation statement is not within a try/catch block. c)'ls /' will return a list that does not include 'myFile'. d)'ls /' will return a list that includes 'myFile'. e)The program could not have compiled because there is no java.util import. :: c ?? 60 Which entry lists all of the valid File constructors (excluding File(URI uri)? a)File(File f),File(String p). b)File(Dir d, String n),File(String p),File(String d,String n). c)File(File f1,File f2),File(File f,String n) d)File(File f,String s),File(String p),File(String s1,String s2). e)File(File f,String s),File(String p),File(File d,File f). :: d ?? 60 Given this code fragment: File f = new File("file"); try { FileWriter fw = new FileWriter(f); byte[] b = { 7,3 }; fw.write(b); char[] ch = {'c','d'}; fw.Write(ch); }catch(IOException ioe) { System.out.println(ioe.getMessage()); } What is the result of the code? (Choose one answer) a)Compile error--char[] ch is an illegal argument to FileWriter.write(). b)byte[] b and char[] ch are written to the file which exists in persistent storage when the program exits. c)Compile error--byte[] b is an illegal argument to FileWriter.write(). d)byte[] b and char[] ch are written to the file, but when the program exits file ceases to exists. e)The byte[] argument is promoted to int[] in the write() invocation which is then printed to the file as a numeral. :: c ?? 90 Construct a BufferedWriter with what type of stream? (Choose one answer) a)OutputStream. b)OutputStreamReader. c)Writer. d)ByteStream. e)FileOutputStream. :: c ?? 30 What significant improvements does BufferedWriter provide over FileWriter? (Choose one answer) a)Drops synchronized methods, so it runs faster. b)Adds the 'println()' method to accomodate writing whole lines. c)None--BufferedWriter is a subclass of FileWriter. d)Allows for encrypted write() calls. e)Faster and also has 'newLine()' method to accomodate platform- specific newline characters. :: e ?? 60 Which are not constructors for the PrintWriter class? (x,y,z--no spaces) a)PrintWriter(File file). b)PrintWriter(File dir,File file). c)PrintWriter(String filename). d)PrintWriter(Writer out). e)PrintWriter(OutputStream out). f)All are valid PrintWriter constructors. :: b ?? 60 Can you call printf()/format() on a BufferedWriter? a)yes b)no :: b ?? 30 Can you call printf()/format() on a PrintWriter? a)yes b)no :: a ?? 30 Given: try { BufferedReader bf = new BufferedReader(new FileReader("myfile")); ____ = bf.read(); //line 1 bf.close(); }catch(IOException ioe) { System.err.println(ioe.getMessage()); } What is the datatype returned by read() and assigned to the blank in line one? (Choose one answer) a)char. b)byte. c)int. d)Character. e)byte[]. :: c ?? 60 What are the arguments to the method described below? BufferedReader bf = new BufferedReader(new FileReader()); bf.read(buff,0,10); (Choose one answer) a)char array, minimum number of chars to read, maximum number of chars to read. b)char array, delay to read, seconds to timeout (after reading begins). c)byte array, offset to begin copy to byte array, length to copy into byte array. d)Destination file, minimum number of chars to read, maximum number of chars to read. e)char array, offset to begin copy to char array, length to copy into char array. :: e ?? 60 BufferedWriter does not provide 'writeLine()' or 'printLine()' methods. Does BufferedReader support a 'readLine()' method? a)yes. b)no. :: a ?? 30 Which option does not contain a false constructor for FileReader? (Choose one option) a)FileReader(File dir,String name),FileReader(File file). b)FileReader(File file),FileReader(String name). c)FileReader(String dir,String name),FileReader(File dir,File name), FileReader(Dir d,String name). d)FileReader(File dir,File file),FileREader(String name). e)FileReader(File file,String name),FileReader(String name), FileReader(Dir d,String name). :: b ?? 60 Given this code fragment: StringBuilder sb = new StringBuilder("mfg"); StringBuilder sB = new StringBuilder("mfg"); System.out.println(sb.equals(sB)); What prints? a)true. b)false. c)Compile error--StringBuilder doesn't have the equals() method. :: b ?? 30 Given this code fragment: String s1 = "mlp"; StringBuffer sb = new StringBuffer("mlp"); s1.concat("-naked"); sb.append("-naked"); System.out.println(s1 + " " + sb); What prints? (Choose one option) a)'mlp mlp-naked'. b)'-naked mlp-naked'. c)'mlp-naked mlp-naked'. d)Compile error--unknown symbol String.concat(String). e)None of the above. :: a ?? 60 Given this code fragment: StringBuilder sb = "1c43d0"; sb.delete(2,3); sb.concat("--"); sb.reverse(); sb.instert(1,"bcn"); System.out.println(sb); What prints? (Choose one option) a)Compile error. b)-bcn-0d3c1. c)-bcn-0dc. d)--bcn0dc. e)--bcn0d3c1. :: a ?? 120 What is true about StringBuilder/Buffer methods and String methods? (x,y,z--no spaces) a)It is generally the case in methods with two indexes as arguments that the first index is inclusive and the second is exclusive. b)'length()' is a method of String, but StringBuilder/Buffer use the length *field* 'length'. c)StringBuilder/Buffer have the toString() method, but String does not. d)Both String and StringBuilder/Buffer have the delete() method. e)Both String and StringBuilder/Buffer override equals() so that their strings are compared to determined equality. f)Both String and StringBuilder/Buffer have the insert method. g)reverse() is exclusively a StringBuffer/Builder method. :: a,g ?? 120 Given: public class Strings { public static void main(String...args) { String s1 = "boxer"; String s2 = "boxer"; String s3 = new String("boxer"); s3.toUpperCase(); } } How many unique objects are created? (Choose one answer) a)0 b)1 c)2 d)3 e)4 :: d ?? 60 Given: class Grynphul { String name = "fred"; } public class Tester { public static void main(String[] args) { Grynphul g1 = new Grynphul(); Grynphul g2 = new Grynphul(); System.out.println(g1.equals(g2)); } } What is the result? (Choose one answer) a)Compile error--unknown symbol equals(). equals() hasn't been defined or overridden in Grynphul and so cannot be called. b)The program compiles but since equals() hasn't been overridden, the empty implementation runs and nothing prints. c)The program compiles and prints 'true'. d)the program compiles and prints 'false'. e)Runtime exception. :: d ?? 60 Given: class Grynphul { String name; Grynphul(String n) { this.name = n; } public boolean equals(Object o) { if ((o instanceof Grynphul) && (((Grynphul)0).name==this.name)) { return true; } else { return false; } } } What is true about this code? (x,y,z--no spaces) a)The class will compile and run without error. b)The implementation of the equals() method violates the equals contract. c)The class will not compile because it fails to override hashCode(). d)Using generics, the equals method could have been written so that the argument was of type Grynphul, not the "generic" object class. e)The equals() method now tests whether objects calling it really are just other references to the same object. :: a,d ?? 90 The equals contract provides: that equals() will return false if it is passed null, unless the reference calling equals is null; that at any time equals() will return the same result for two operands; that equals() will be "reflexive--for any ref x, x.equals(x) will return true; that equals() will be "transitive"--for any references x,y and z, if x.equals(y) returns true and x.equals(z) returns true, x.equals(z) will return true. In one (lowercase) word, enter the missing stipulation of the equals() contract: :: symmetric ?? 90 Which contract effectively requires that if equals() is overridden, hashCode() must also be overriden? a)equals contract b)hashCode contract :: b ?? 30 What is true about the hashcode contract? (x,y,z--no spaces) a)It specifies that hashcodes must be reflexive--any instance of a given class must have the same hashcode as any other instance. b)It specifies that all objects must implement the hashcode interface and its primary method, hashcode(). c)It stipulates that if two objects are equal according to the equals method, they may or may not have the same hashcode value. d)It stipulates that hashcodes must be consistent between calls in the same running of an application--the hashcode returned from a given object must be the same. e)It specifies that hashcodes must be calculated using the memory address of the object. :: d ?? 90 True or false: the best hashcodes will return unique values the greatest percent of the time they are called. a)true b)false :: a ?? 30 Given: class GetCode { public int hashCode() { return 7; } } What is true about the foregoing class? (x,y,z--no spaces) a)It will not compile. b)Its hashcode implementation will compile, but violates the hashcode contract. c)It will compile and is consistent with the hashcode contract. d)It won't compile because it doesn't implement the hashcode interface. e)It is a relatively ineffective implementation of hashcode(). :: c,e ?? 60 Given: public class Grynphul { transient int weight; String name; int size; Grynphul(int w,int s,String n) { this.weight = w; this.size = s; this.name = n; } public boolean equals(Object o) { if ((o instanceof Grynphul) && ((Grynphul)o).name.equals(this.name)) { return true; } else { return false; } } public int hashCode() { int code = 0; //__________; return code; } } Which code fragment below, when put in the blank in hashCode() above, would render that method most useful and effective, while not violating the hashcode contract? (Choose one option) a)code = 78 b)code = name.length() + weight c)code = name.length() d)code = (int)(name.length() * Math.random()) e)code = size / weight; :: c ?? 90 Given: import java.util.*; public class Natural { public static void main(String[] args) { String[] strings = new String[6]; strings[0] = " spy"; strings[1] = "spy"; strings[2] = " Spy"; strings[3] = " 1spy"; strings[4] = " "; strings[5] = "1"; TreeSet set = new TreeSet(); for (String s:strings) set.add(s); for (String s:set) System.out.println(s); } } Identifying each string by it's index in 'strings', in what order will the strings be printed by the class above? (Choose one answer) a)2,1,0,3,5,4 b)4,3,2,0,5,1 c)5,4,3,0,2,1 d)4,2,0,3,1,5 e)The order cannot be predicted. :: b ?? 120 Given: import java.util.*; class RockStar implements Comparable { String name; int popularity; int coolness; void jam() { System.out.println("BLOUGH!!!eeeeEEEEZZZZWaaaAAAHHHdiddlediddlewoooOOO!"); } public int compareTo(Object o1) { RockStar star1 = (RockStar)o1; //int order = star1.name.compareTo(this.name); int order = (o1.popularity+o1.coolness) - (this.popularity+this.coolness); return order; } RockStar(String n,int p,int c) { this.name = n; this.popularity = p; this.coolness = c; } } public class RockTest { public static void main(String[] args) { TreeSet ts = new TreeSet(); ts.add(new RockStar("Keef",81,90)); ts.add(new RockStar("Mick",81,89)); ts.add(new RockStar("Charlie",48,120)); ts.add(new RockStar("Ron",60,107)); ts.add(new RockStar("Daryll",10,10)); for (RockStar rs:ts) System.out.println(rs.name); System.out.println("Jam!!"); new RockStar("Joe",47,123).jam(); } } In what order will the Rockstars appear in the output? (Choose one answer) a)Mick,Keef,Ron,Charlie,Daryll b)Daryll,Ron,Charlie,Mick,Keef c)Charlie,Ron,Keef,Mick,Daryll d)Keef,Mick,Charlie,Ron,Daryll e)Charlie,Daryll,Keef,Ron,Mick f)John,Paul,George,Ringo :: d ?? 240 Given: class RockStar implements Comparable { String name; int popularity; int coolness; void jam() { System.out.println("BLOUGH!!!eeeeEEEEZZZZWaaaAAAHHHdiddlediddlewoooOOO!"); } public int compareTo(Object o1) { RockStar star1 = (RockStar)o1; //<------LINE A int order = (star1.popularity+star1.coolness) - (this.popularity+this.coolness); return order; } RockStar(String n,int p,int c) { this.name = n; this.popularity = p; this.coolness = c; } } What would eliminate the need for 'LINE A' in the code above? (x,y,z--choose all that apply, no spaces) a)'LINE A' isn't required anyway. b)Implement Comparable generically by appending '' to 'Comparable' and then make the compareTo() parameter a RockStar type rather than an Object type. c)Include a field variable of type RockStar, name it o1, and make compareTo a standard method called by the constructor. d)Implement Comparable generically by changing the argument to compareTo() to 'compareTo( star1)'. e)There is no way to get around the need for 'LINE A'. :: b ?? 90 Which are valid methods of obtaining a sorted Collection of custom objects of the same class? (x,y,z--Choose all that apply, no spaces) a)Create an array of the objects, pass the array to Arrays.sort(), and then create a List from the resulting array. b)Add the objects to the Collection in the sequence desired. c)Put the objects in a 'tree'-collection, either 'TreeSet' or 'TreeMap'. d)If the objects implement Comparable, put them in a 'tree'- collection, either 'TreeSet' or 'TreeMap'. e)If the objects do not implement Comparable, define a Comparator class, implement its compare() method, and create either a List, Set, or Map with the Comparator and of the same generic type as the objects, and put the objects in this collection. f)There is no way to guarantee that the objects will be sorted in any kind of collection unless both the objects and the collection implement 'Sortable'. g)If the objects do not implement Comparable, put the objects in a List, define a Comparator, and pass both the List and the Comparator to Collections.sort(). :: d,e,g ?? 120 True or false: a list of objects may be sorted with the use of a Comparator object even if the objects in the list do not implement Comparable: a)true b)false :: a ?? 30 Enter the method signature of the functional method in the Comparator interface; use this format: [access modifier] TYPE NAME([ARGTYPE] "a1"[,]) //<--use first initial of //arg class for ref name, //then number beginning 1~ so that your entry does not include the opening '{' bracket :: public int compare(Object o1,Object o2) ?? 90 Given: import java.util.*; class ComparIt implements Comparator { public int compare(RockStar rs1,RockStar rs2) { int sort = -1*((rs1.popularity+rs1.coolness) - (rs2.popularity+rs2.coolness)); return sort; } } class RockStar { String name; int popularity; int coolness; void jam() { System.out.println("BLOUGH!!!eeeeEEEEZZZZWaaaAAAHHHdiddlediddlewoooOOO!"); } RockStar(String n,int p,int c) { this.name = n; this.popularity = p; this.coolness = c; } } public class Compator { public static void main(String[] args) { RockStar[] stars = new RockStar[4]; stars[0] = new RockStar("Bootsy",3,165); stars[1] = new RockStar("Avril",69,80); stars[2] = new RockStar("Axel",20,149); stars[3] = new RockStar("Jimmy",60,110); ArrayList list = new ArrayList(); for (RockStar rs:stars) list.add(rs); ComparIt ci = new ComparIt(); Collections.sort(list,ci); System.out.println("TOP 4"); for (RockStar rs:list) System.out.println(rs.name); } } What will the ranking of the top four be? a)Avril,Bootsy,Axel,Jimmy b)Jimmy,Axel,Bootsy,Avril c)Jimmy,Jimmy,Jimmy,Jimmy d)Bootsy,Axel,Jimmy,Avril e)Andy,Gordon,Stewart :: b ?? 180 What is true about sorting arrays? (x,y,z--choose all that apply, no spaces) a)Arrays can be sorted by implementing Comparable. b)Primitive arrays sort by natural order via the Arrays.sort() method. c)Arrays cannot be sorted in Java. d)Arrays are sorted using Arrays.sort([?])--using appropriate arguments. e)Arrays of primitives can be sorted, but arrays of objects cannot. f)Object arrays will sort if they implement Sortable and they are passed to the Arrays.sort() method, or if a Comparator object is passed to Arrays.sort() along with the array reference. g)Arrays can be sorted via the sortArr() method, in Arrays. :: b,d ?? 120 Given the following code fragment: String[] strings = { "one","two","three" }; List list = _________; Enter the code that must go in the blank to create a list from the array 'strings': (omit the semicolon) :: Arrays.asList(strings) ?? 60 Given: import java.util.*; public class Lists { public static void main(String[] args) { String[] strings = { "one","two","three" }; List list = Arrays.asList(strings); strings[0] = "five"; for(Object o:list) System.out.print((String)o + " "); } } What is the result of this code? (Choose on answer) a)"one two three ". b)Compile error--can't find symbol 'asList(String array)'. c)Runtime exception. d)"one two five". e)"five two one". f)"five two three". :: f ?? 90 what is the correct expression of the algorithm for the index that the binarySearch method returns for an unsuccessful search? (Choose one answer) n = insertion point of term. a)1-(n-1). b)A = P(1+r/n)^nt. c)-(n+1). d)-(n-1). e)-(--n-1). :: c ?? 90 Given two String arrays, what is an efficient way to tell if they have the same elements at the same index positions? (Choose one answer) a)Set up a loop to iterate through each simultaneously and use equals() to compare each index position's String. b)Use the '==' operator with the arrays as operands. c)Call equals() on one array and pass it the other array. d)Call Arrays.equals(array1,array2). e)Attempt to assign one array to the other array's reference variable. If there is no exception, the arrays are equal. :: d ?? 60 Given this code fragment: Integer[] INTS = { new Integer(0),new Integer(1),new Integer(2) }; int[] ints = { 0,1,2 }; System.out.println(Arrays.equals(INTS,ints)); What prints? (Choose one answer) a)"true" b)"false" c)Nothing prints. d)NullPointerException e)Compile error--cannot find symbol equals(Integer[],int[]). :: e ?? 60 Given: import java.util.*; public class ToArTest { public static void main(String...args) { Integer[] INTS = new Integer[3]; ArrayList list = new ArrayList(); for (int i = 0;i < 3; i++) list.add(i); INTS = Collections.toArray(list); for (Integer i:INTS) System.out.print(i + " "); } } What is the output? (Choose one answer) a)0 1 2. b)Compile error--can't find symbol toArray(ArrayList). c)Runtime Exception. d)An empty line prints. e)Integer@0x3344 Integer@0x11333 Integer@0x33112 (or similar). :: b ?? 60 Given: import java.util.*; public class ReversIt { public static void main(String...args) { ArrayList list = new ArrayList(); for (int i = 0; i < 3; i++) list.add(i); Collections.reverseOrder(list); for (String s:list) System.out.print(s + " "); } } What prints? (Choose one answer) a)0 1 2. b)2 1 0. c)Integer@0x135871 Integer@0x33119 Integer@779193 (or something similar). d)Runtime Exception. e)Compile error--can't find symbol reverseOrder(ArrayList). :: e ?? 60 Given: import java.util.*; class Legacy { int CountChars(List list) { int count = 0; for (int i=0;i list = new ArrayList(); for (int i = 0;i<3 ; i++) list.add(new Integer(i).toString()); System.out.println("Total chars is " + l.CountChars(list)); } } What is the result of this code? (Choose one answer) a)The code compiles and prints 'Total chars is 3'. b)The code compiles and prints 'Total chars is 0'. c)The code compiles with warnings and prints 'Total chars is 0'. d)The code compiles with warnings and prints 'Total chars is 3'. e)Compile error--imcompatible types Object and String. f)Compile error--cannot pass generic collection to non-generic method. :: d ?? 120 Is the assignment valid?: ArrayList nums = new ArrayList(); (Choose one answer) a)yes b)no :: b ?? 30 What is true about generics? (x,y,z--no spaces) a)'?' is a symbol indicating that the suitable type for a given entity is unknown. b)'? super [type]' means 'take anything that is a superclass of [type] or [type] itself. c)'? extends [type]' means 'take anything of [type] or that extends type'. d)The '?' symbol may appear on either side of the assignment operator when declaring and initializing collections. e)A generic collection declared with syntax may be manipulated (added to) by method code without generating compiler warnings. f)A method with a parameter such as List may take any sort of list, but if the list is added to in the method, compile warnings will be generated. :: b,c,e ?? 90 Enter an equivalent generic collection description to List: :: List ?? 60 Given this code fragment: List list = new ArrayList(); public void doIt(List list) { ___ } What can legally be passed to the method, and what can be done to 'list' in the method code? (Choose one answer) a)Any type of list can be passed in, and anything can be done to the list that is passed in. b)It is not known what can go in the list--this must be seen to in the other part of the program. Anything can go in the blank. c)Any type list can be passed in, but no modifications may be performed on the list or there will be compiler error. d)Any type list can be passed in, but no modifications may be performed on the list or there will be a runtime exception. e)None of the above. :: c ?? 90 Which are incorrect statements regarding generics in Java? (x,y,z--no spaces) a)There are no polymorphic assignments of generic objects. b)Any method that has an argument like 'List list' cannot alter the object with add() methods and the like, or there will be a compiler error. c)Any method that has an argument like 'List' cannot alter the object with add() methods and the like, or there will be a compiler error. d)Generic collections can be used with legacy code, but the compiler will generate warnings if the legacy code adds anything to the generic collection that was passed to it. e)Generic collections can be used with legacy code, but the compiler will convert the typed contents to Object type elements. :: c ?? 90 Given: import java.util.*; class WhatThe { List list; public List makeEm(____) { list = new ArrayList(); for (int i=0;i<3;i++) list.add(arg); return list; } } public class TestT { public static void main(String[] args) { WhatThe stars = new WhatThe(); RockStar rs = new RockStar("Ken",100,100); List list = stars.makeEm(rs); for (RockStar rocks:list) System.out.println(rocks.name); } } Assuming RockStar is a valid class in the package 'test', enter exactly what must go in the blank in the 'makeEm' method in order for the file to compile: :: T arg ?? 120 What usually determines the 'type' of a generic method? (Choose one answer) a)The explicit type stated in the argument list. b)The type of the class in which the generic method is found. c)The type of the argument passed into the method. d)Generic methods do not have a 'type'. e)Generic methods are always the same type as the type they return. :: c ?? 60 What is the syntax for multiple-typed generic classes? a) after the class name. b) after the class name. c)2 after the class name. d) (or whatever other types are being used) after the class name. e)None of the above. :: a ?? 60 The Set interface requires that all elements are: (x,y,z--no spaces) a)comparable b)serializable c)unique d)objects e)primitives :: c,d ?? 60 Use of the poll(), peek() and offer() methods could mean that (x,y,z--no spaces) a)A PriorityQue class is being used. b)A LinkedHashSet class is being used. c)A LinkedList is being used. d)A BufferedReader is being used. e)A FileReader is being used. :: a,c ?? 60 'add()' is to List as _____() is to Queue. Fill in the blank: :: offer() ?? 30 The _________ class is better for implementing a stack than the ArrayList class. Fill in the blank: :: LinkedList ?? 30 Which class is best if there will be frequent insertions and deletions (as opposed to simple iteration) (Choose one answer) a)LinkedArray b)It doesn't matter. c)Vector d)LinkedList e)ArrayList :: d ?? 30 Given this code fragment: Iterator ri = rs.iterator(); while (ri.hasNext()) { ... What Java construct accomplishes the same thing as above with less code? a)The for loop. b)The enhanced while loop. c)The labled do-while loop. d)The itorate interface. e)The enhanced for-loop. :: e ?? 60 Sets do no allow duplicates. If you attempt to add a duplicate to a Set: a)There will be a runtime exception. b)The Set will have difficulty finding its elements. c)Compiler error. d)The operation will return -1. e)The operation will return false; :: e ?? 60 Given: import java.util.*; class Bobble { int bobFactor; int bobType; String bobStyle; Bobble(int f,int t, String s) { this.bobFactor = f; this.bobType = t; this.bobStyle = s; } public boolean equals(Object o) { if ((o instanceof Bobble) && (((Bobble)o).bobFactor == this.bobFactor)) { return true; } else { return false; } } public int hashCode() { return bobFactor + bobType; } } public class DoSets { public static void main(String...args) { Set set = new HashSet(); //LINE A set.add(new Bobble(0,1,"ripple")); //LINE B set.add(new Bobble(1,1,"ripple")); set.add(new Bobble(2,1,"skip")); set.add(new Bobble(0,1,"wiggle")); //LINE C for (Bobble b:set) //LINE D System.out.print(b.bobFactor + ": " + b.bobStyle + "||"); } } What is the result of this code? (Choose one answer) a)The program compiles and prints 0: ripple 1: ripple 2: skip 0: skip b)The program compiles and prints 0: ripple 1: ripple 2: skip c)Compile error at LINE A. d)Compile error at LINE B. e)Compile error at LINE C. f)Compile error at LINE D. g)Runtime exception at LINE C. :: f ?? 120 Given: import java.util.*; class Bobble { int bobFactor; int bobType; String bobStyle; Bobble(int f,int t, String s) { this.bobFactor = f; this.bobType = t; this.bobStyle = s; } public boolean equals(Object o) { if ((o instanceof Bobble) && (((Bobble)o).bobFactor == this.bobFactor)) { return true; } else { return false; } } public int hashCode() { return bobFactor + bobType; } } public class BobTest { public static void main(String[] args) { Set set = new TreeSet(); //line 1 set.add(new Bobble(1,0,"shake")); //line 2 set.add(new String("wiggle")); //line 3 set.add(new Bobble(0,1,"twitter")); //line 4 set.add(new Bobble(1,0,"shake")); //line 5 for (Bobble b:set) //line 6 System.out.print(b.bobStyle + " ")); } } What is the result? (Choose one answer) a)Compiles and prints "shake wiggle twitter shake". b)Compiles and prints "shake wiggle twitter". c)Compiles and prints shake, wiggle and twitter but not necessarily in that order. d)Compile error at line 5. e)Compile error at line 4. f)Runtime exception at line 1. g)ClassCastException at line 3. h)None of the above. :: h ?? 120 True or false: a sorted collection will throw a ClassCastException if the add() method is called with an object of some other type than the generic type of the set? a)true b)false :: b ?? 30 True or false: a sorted collection of a type of object that does not implement Comparable) will throw a ClassCastException when the add() method is called with such an object? a)true b)false :: a ?? 30 Given: class Bobble { int bobType; String bobStyle; Bobble(int t,String s) { this.bobType = t; this.bobStyle = s; } } public class MapTest { public static void main(String...args) { Map map = new TreeMap(); map.put(new Bobble(0,"wiggle"),0); map.put(new Bobble(1,"skip"),1); map.put(new Bobble(1,"wobble"),2); Bobble bKey = new Bobble(1,"wobble"); System.out.println(map.get(bKey)); } } What will be the result of this code? (Choose one answer) a)The code compiles without exceptions and prints 2 b)The code compiles without exceptions and prints null c)The code compiles but throws and exception at runtime. d)The code compiles but throws a ClassCastException at runtime. e)None of the above. :: b ?? 90 What is true about HashMap and HashSet? (x,y,z--no spaces) a)Objects are stored according to hashCode; if more than one object in the collection have the same hashcodes, their equals() method will determine whether they are unique. b)Objects are stored sequentially in memory, ensuring that they are unique. c)Attempting to add instances of classes that do not override hashCode and equals() to HashSet or HashMap will result in compiler error. d)If an object's hashCode returns the same value as another element of a given collection, the add() method will return false and the object will not be added to the collection. e)The default hashCode method virtually always comes up with a unique number for each object. :: a,e ?? 90 What is true about Maps? (x,y,z--no spaces) a)The Maps are comprised of HashMap, TreeMap, and LinkedHashMap. b)The way to tell whether a given object is a key in a map is to call get([object]) on the map--either a value will be returned, or false will be returned. c)In contrast to the situation with LinkedList and ArrayList, LinkedHashMap iterates FASTER than HashMap, but it is SLOWER for adding/removing operations. d)All Maps require unique keys, one of which may be null. e)None of the Map implementation classes offer synchronized methods. f)Hashtable doesn't use camel-case, in distinction to virtually all other API class names. :: c,f ?? 120 What is not true about assertions? (x,y,z--no spaces) a)Assertions contain two basic components: the boolean expression and the optional message that prints with the stack trace. b)The message portion of an assertion statement is optional. c)If the message portion of an assertion is included, it is separated from the boolean portion by a colon. d)If the message portion of an assertion is included, it can resolve to null, but it cannot be void (ie a void method call). e)Assertions are disabled by default and must be enabled using the shorthand '-ea' upon invocation of the program. f)You should never use assertions to validate a public method, except to check cases that should NEVER happen. g)Never *change* anything in the boolean expression. h)Assertions are useful. :: h ?? 90 'com.invest.main' is the main class for an investment program that also utilizes classes from the com.cUtils package. You want to invoke the program and enable the assertions in the com.invest package, but not in the com.cUtils package. If your file system looks like java/com/invest and java/com/cUtils, invoke the program from the /com directory, using the '-ea' shorthand for the -enableassertions flag, and the '-cp' shorthand for the -classpath flag. Begin the command with 'java -ea': :: java -ea:../com.invest... -cp ../ com.invest.main ?? 120 Given: public class Asserts { public static void main(String[] args) { int assert = 7; System.out.println("assert is " + assert); } } What will result from attempting to compile and run this program, using the -source 1.3 flag? (Choose one answer) a)The program will compile successfully and print assert is 7 b)The program will compile successfully and print [nothing] c)The program will compile but will throw a KeywordException at runtime. d)The program will have one compile error and warnings. e)The program will compile successfully but with warnings and print assert is 7 :: e ?? 90 List, in alphabetical order, separated by commas, with no spaces, every single modifier (including access modifiers--the list will be wider than your screen): :: abstract,final,native,private,protected,public,static,strictfp,synchronized,transient,volatile ?? 90 What non-access modifiers cannot be applied to regular inner classes? (enter a comma-separated, alphabetical list with no spaces) :: native,static,synchronized,transient,volatile ?? 90 Given: public class DoInner { private int code = 7; class CodeBreaker { void breakIt() { System.out.println("The code is " + code); } } class Dummy { String dummy = "dummy"; } void DoDummy() { Dummy d1 = ____________; //blank 1 System.out.println(d1.dummy); } public static void main(String[] args) { DoInner di = new DoInner(); DoInner.CodeBreaker cb = __________; //blank 2 cb.breakIt(); di.DoDummy(); } } There are two blanks in the code above. On the same line, enter the code to fill in the first blank, then a space, then the code for the second blank. Do not enter the semicolons: (code1() code2()) :: new Dummy() di.new CodeBreaker() ?? 120 Given: package myPack; interface Routines { void shake(); String rattle(); } public class DoInner { Routines r = new Routines() { public void shake() { System.out.println("shake"); } public String rattle() { return "rattle"; } public void myNewMeth() { System.out.println("new method"); } }; public static void main(String[] args) { DoInner di = new DoInner(); di.r.myNewMeth(); } } What is the output of this program? (Choose one answer) a)The program compiles and prints 'new method'. b)The program compiles and prints nothing. c)The program compiles but there is a runtime exception. d)Compile error--can't find symbol myNewMeth(). e)Compile error--you cannot instantiate an interface. :: d ?? 120 Given: class FlangOMatic { void doAll() { } public static void main(String[] args) { FlangOMatic fo = new FlangOMatic(); System.out.println(fo.getName()); } String getName() { int factor = 7; Flanger fl = new Flanger(); return fl.doName(); class Flanger { String doName() { return "fName" + 7; } } } What is the result of this code? (Choose one answer) a)The code compiles and prints 'fName7'. b)The code compiles and prints '7'. c)There is a runtime exception. d)Compiler error--can't find symbol Flanger. e)Some other compiler error. :: d ?? 90 Enter a comma-separated, alphabetical list (with no spaces) of the allowable modifiers for a method-local inner class: :: abstract,final ?? 90 Given: class DoLittle { int x = 7; void nudge() { System.out.println("nudge"); } } public class OddMeth { int x = 7; public static void main(String[] args) { OddMeth om = new OddMeth(); om.doIt(new DoLittle() { void nudge() { System.out.println("wink"); } }); } void doIt(DoLittle dl) { dl.nudge(); } } What is the result of the code? (Choose one answer) a)The code compiles and prints 'wink'. b)The code compiles and prints 'nudge'. c)There is a runtime exception. d)Compile error--can't find symbol nudge. e)None of the above. :: a ?? 90 Given: class HasStatic { int x = 7; static class AStatic { String status = "static!"; } } public class DoesStatic { public static void main(String[] args) { HasStatic.AStatic ha = _________; System.out.println(ha.status); } } Enter the code that must go in the blank in order for the classes to compile and print 'static!': :: new HasStatic.AStatic() ?? 90 Given: Given: class HasStatic { int x = 7; static class AStatic { String status = "static!" + x; } } public class DoesStatic { public static void main(String[] args) { HasStatic.AStatic ha = new HasStatic.AStatic(); System.out.println(ha.status); } } What will the result of this code be? (Choose one answer) a)Compiles and prints 'static!7'. b)Compiles and prints 'static!'. c)Compiler error--can't find symbol x. d)Runtime exeption. e)Another compiler error. :: c ?? 60 What is true about creating threads in Java? (x,y,z--no spaces) a)Threads are created exclusively by extending the Thread class. b)Threads can be initialized with any class that implements Runnable. c)Threads can extend any class. d)The same run() method can be used by different threads. e)A thread can be created that uses the run() implementation of an existing instance of Thread. :: d,e ?? 90 Given: class Runner implements Runnable { public void run() { System.out.print("Ready "); } public class Threaded extends Thread { public void run() { System.out.println("go!!"); } public static void main(String[] args) { Threaded th = new Threaded(); Runner rn = new Runner(); Thread t1 = new Thread(rn); t1.start(); System.out.print("set "); th.start(); } } What is the output of this code? (Choose one answer) a)'Ready set go!!'. b)The output is unpredictable. c)Compiler error--can't find symbol 'start()' for Threaded. d)'set Ready go!!'. e)Compiler error--uncaught exception generated by call to start(). :: b ?? 90 Given: public class ThreadIt extends Thread { public void run() { try { sleep(1000); }catch (InterruptedException ie) { System.err.println(ie.getMessage()); } System.out.print(currentThread().getName() + ": I'm awake! "); } public static void main(String[] args) { ThreadIt t1 = new ThreadIt(); t1.f(); System.out.println("Done."); } void f() { run(); } } What is the result of this code? (Choose one answer) a)The program compiles and prints 'main: I'm awake! Done.'. b)Compiler error--illegal call to run() in f(). c)IllegalThreadStateException thrown by call to run() in f(). d)The program compiles and prints 'Thread-0: I'm awake! Done.'. e)Compile error--can't find symbol sleep(). :: a ?? 120 Given: class MyRun implements Runnable { public synchronized void run() { System.out.print(Thread.currentThread().getName() + ": running. "); } } public class DoRunRun { public static void main(String[] args) { MyRun mr = new MyRun(); Thread t1 = new Thread(mr,"1"); //line 1 Thread t2 = new Thread(new MyRun(),"2"); //line 2 Thread t3 = new Thread(mr,"3"); //line 3 t3.start(); //line 4 t1.start(); //line 5 t2.start(); //line 6 } } what is true about the code above? (x,y,z--no spaces) a)The use of the 'synchronized' keyword in the run() method is illegal. b)After line 3 but before line 4, threads 1,2 and 3 are all in the 'runnable' state. c)After line 3 but before line 4, threads 1,2 and 3 are all alive. d)The program compiles and the output is 3: running. 1: running. 2: running. e)The output of the program cannot be determined because the thread scheduler will not necessarily run the threads in the same order they were started. :: c,e ?? 120 Given: public class Threader extends Thread { DoStuff df = new DoStuff(); Threader (String n) { super(n); } Threader (Runnable runner,String n) { super(runner,n); } public synchronized void run() { System.out.println(currentThread().getName() + ": in run. "); df.f(); } public static void main(String[] args) { Thread t1 = new Threader("one"); Thread t2 = new Thread(t1,"two"); Threader t3 = new Threader("three"); t1.start(); try { t1.join(); }catch(InterruptedException ie) { System.err.println(ie.getMessage()); } t3.start(); t2.start(); } } class DoStuff { int x = 7; Integer block = new Integer(7); void f() { synchronized (this) { try { System.out.println(Thread.currentThread().getName() + ": Start. "); Thread.sleep(500); System.out.println(Thread.currentThread().getName() + ": Finish. "); }catch (InterruptedException ie) { System.err.println(ie.getMessage()); } x += x; } } } Barring some very unusual allocations by the thread scheduler, what is likely to be the output of this program? (Choose one answer) a)one: in run. b)one: in run. c)one: in run. d)one: in run. e)None of one: Start. one: Start. one: Start. three: in run. these. one: Finish. two: in run. Three: in run. two: in run. three: in run. two: Start. Three: Start. three: Start. three: Start. one: Finish. Three: Finish. two: Start. two: in run. three: in run. one: Finish. three: Finish. two: Start. three: Start. two: in run. two: Finish. three: Finish. two: Finish. two: Start. one: Start. two: Finish. three: Finish. two: Finish. one: Finish. :: a ?? 210 Enter the various thread states in an alphabetical, comma-separated list, with no spaces: (ie. one,three,two) :: alive,dead,new,runnable,running ?? 90 Is a new thread alive? a)yes b)no :: b ?? 30 There are several ways for a thread to enter the runnable state, but only one way to enter the ________ state. :: running ?? 30 A thread is dead when its run() method __________ . (Enter the word--no punctuation) :: completes ?? 30 What is true about threads and thread-related methods? (x,y,z--no spaces) a)Once a thread is started, it remains started for the life of the program. b)public void run() can only be called by the JVM--any attempt to programmatically call run() will result in compiler error. c)join() is a non-static method of Thread that must be called from a synchronized context. d)protected void run() is a method of Thread that can be called programmatically as well as by the JVM. e)A thread will return to running as soon as its sleep milliseconds interval has expired. f)None of the above are true. :: f ?? 120 Given: public class IceCream2 { private int cherry; private int anise; private int vanilla; private float accountsR; private float Price = 5.99f; Thread c1; Thread c2; Thread c3; IceCream2(int c,int a,int v) { cherry = c; anise = a; vanilla = v; accountsR = 0.0f; } public int[] getInv() { int[] Inv = { cherry,anise,vanilla }; try { Thread.sleep(500); }catch(InterruptedException ie) { System.err.println(ie.getMessage()); } return Inv; } public void doOrder(int c,int a,int v) { int[] order = { c,a,v }; int[] inv = getInv(); boolean b = true; System.out.print(Thread.currentThread().getName() + " placed an order "); System.out.print("for " + order[0] + " Cherry, " + order[1] + " Anise "); System.out.println("and " + order[2] + " Vanilla."); for (int i = 0; i < inv.length; i++) { if (order[i]>inv[i]) { System.out.println("You can't order " + order[i] + " tubs because we "); System.out.println("only have " + inv[i] + " tubs of that flavor"); System.out.println("in stock."); System.out.println("Please resubmit your modified order."); b = false; break; } } if (b) { cherry -= order[0]; anise -= order[1]; vanilla -= order[2]; accountsR += (order[0] + order[1] + order[2])*Price; System.out.print(Thread.currentThread().getName() + "'s order has "); System.out.println("been filled."); } b = true; } public static void main(String args[]) { IceCream2 ic = new IceCream2(8,8,12); IceCream2.Running rr = ic.new Running(); ic.c1 = new Thread(rr,"Amber"); ic.c2 = new Thread(rr,"Kristina"); ic.c3 = new Thread(rr,"Rachel"); System.out.print("Today we have " + ic.cherry + " cherry, " + ic.anise); System.out.println(" anise, and " + ic.vanilla + " vanilla tubs."); ic.c1.start(); ic.c2.start(); ic.c3.start(); try { ic.c1.join(); ic.c2.join(); ic.c3.join(); }catch(InterruptedException ie) { System.err.println(ie.getMessage()); } System.out.println("Ending inventory: "); int[] eInv = ic.getInv(); System.out.print("Cherry: " + eInv[0] + " Anise: " + eInv[1]); System.out.println(" Vanilla: " + eInv[2]); System.out.printf("Total sales: \n$%.2f\n",ic.accountsR); } class Running implements Runnable { public void run() { doOrder(3,3,5); } } } What is true about this code? (x,y,z--no spaces) a)Synchronization is necessary to make sure that the inventory remains the same between the time doOrder looks up inventory and the time that it subtracts the order from inventory. b)Synchronizing the run() method would be sufficient to make sure that the subtraction from inventory is always based on accurate information. c)Synchronizing the doOrder() method would be sufficient to make sure that the subtraction from inventory is always based on accurate information. d)Synchronizing the getInv() method would be sufficient to make sure that the subtraction from inventory is always based on accurate information. e)Synchronization would make no difference in this program whatsoever. :: a,b,c,d ?? 300 Given: public class UseWait extends Thread { Thread t1; Thread t2 = new Thread() { public void run() { System.out.println(currentThread().getName() + " starting to wait."); synchronized (UseWait.this) { try { UseWait.this.wait(); }catch(InterruptedException ie) { System.err.println(ie.getMessage()); } System.out.println(currentThread().getName() + " done waiting."); } } }; public synchronized void run() { System.out.println(currentThread().getName() + " in run()."); try { sleep(1000); }catch(InterruptedException ie) { System.err.println(ie.getMessage()); } System.out.println(currentThread().getName() + " notifying Thread-1."); notify(); } public static void main(String[] args) { UseWait uw = new UseWait(); uw.t1 = uw; uw.t2.start(); uw.t1.start(); } } What is true about this code? (x,y,z--no spaces) a)The code will compile and run without exceptions. b)The program would run the same without synchronizing anything. c)There will be a compiler error where notify() is called in UseWait's run() method without referencing an object instance via dot-notation. d)The program would run the same if t1 were started before t2 in main(). e)The program will compile and run but it will not terminate successfully as once t2 acquires the lock and calls wait(), t1 will not be able to enter it's synchronized block and call notify(). :: a ?? 180 Given: package test1; public class StatStuff { static public final int MYCONST = 7; public static int doubleIt(int n) { return n * 2; } public void sayIt(String msg) { System.out.println("You said " + msg); } } package test; import static java.lang.Integer.*; import static java.lang.Long.*; import static test1.StatStuff.*; public class ImportStat { public static void main(String[] args) { System.out.print(doubleIt(4) + " "); System.out.print(MYCONST + " "); System.out.print(toBinaryString(8L) + " "); System.out.println(MAX_VALUE); } } What is the result of the code? (Choose one answer) a)The program compiles and runs and prints: 8 7 1000 [a large signed 64-bit number] b)The program compiles and runs and prints: 8 7 1000 [a large signed 32-bit number] c)Compile error--can't find symbols toBinaryString(long) or MAX_VALUE. d)Compile error--ambiguous reference MAX_VALUE. e)Compile error--ambiguous reference toBinaryString(long). f)The program compiles and runs and prints: 8 7 10000 [a large signed 128-bit number] :: d ?? 180 The Properties object is available from what package? :: java.util ?? 30 Given this code fragment: Properties p = System.getProperties(); p.list(_____); What goes in the blank? (Choose one answer) a)an int b)a String c)an inputstream d)an array e)an outputstream f)a console object :: e ?? 30 Given this code fragment: Properties p = System.getProperties(); String val = p.getProperty("myprop","usrNum"); System.out.print(val); and the invocation java -Dmyprop=usrnum [class name] What will the print statement print? (Choose one answer) a)It depends on whether there is a 'myprop' key. b)It depends on whether there is a 'usrNum' key. c)It prints 'usrNum'. d)It prints 'usrnum'. e)The statement prints null. :: d ?? 60 Given: public class DoParams { String name; public static void main(String[] args) { name = args[0]; System.out.println("You indicated your name is " + name); } } What should the code above include to safely accomodate use of the args array? (Choose one answer) a)There is no need to accomodate the args array. b)The size of the args array should first be checked for being greater than zero. c)The assignment statement using the array should be put in try/catch blocks, catching a NullPointerException. d)The args reference should first be checked to see whether it is null. e)The user should be queried as to whether they passed any parameters to the program on invocation. If so, then access args, otherwise do not. :: b ?? 90 Which are valid options for the javac command? (x,y,z--no spaces) a)-D b)-cp c)-d d)-classpath e)-source f)-ea :: b,c,d,e ?? 60 What is true about packages? (x,y,z--no spaces) a)A package is in part a directory in the filesystem where classes and other resources can be found. b)A package name is determined soley by what follows the package statement in a file. c)A package name is derived from one or more directories in the filesystem. d)A package includes all the files in the directories that make up the package name. e)Any class file in a directory that is a package is part of that package. f)The 'fully qualified name' of a class that is part of a package includes each component of the package name and the class name, divided by periods. :: a,c,f ?? 90 What is true about JAR files? (x,y,z--no spaces) a)JAR stands for 'Joint Acting Resource', describing a protocol for linking library files. b)Resources in a JAR file can be accessed without un-JARing the file. c)To reference a file within a JAR archive for the -cp option, you must include the path to the JAR and then the virtual path to the virtual directory in the archive where the file resides. d)Reference a file within a JAR archive for the -cp option by using a path up to and including the JAR file itself. e)Because JAR files are encoded, they must be unJAR'd before accessing any of their files. :: b,d ?? 90 Given: java | ------src | | | -------com | | ------classes -------IceCream | | --------ICMath ---------CalcIt.java | ---------DoMenu.java | --------ICUtils.class You want to compile CalcIt.java, which is in package com.IceCream. CalcIt.java imports package ICMath, from which it uses static methods in ICUtils.class. You are in the /java/src directory. Enter the command to successfully invoke the Java compiler on CalcIt.java and put the resulting class in /java/classes/com/IceCream. Use relative paths where paths must be entered as arguments to javac options. Use abbreviated forms of javac options where possible. Begin with 'javac -d' and proceed from there. :: javac -d ../classes -cp ../classes com/IceCream/CalcIt.java ?? 240 What is true about the process both java and javac use to find supporting files when a classpath is defined? (x,y,z--no spaces) a)The first place they look is in the current directory. b)The first place they look is in the directories defined by the J2SE distribution. c)They both search their list of directories until they find the class they are looking for. If there is a class of the same name in another search path, it will be ignored in favor of the first one found. d)The second place that supporting files are looked for is in the specified classpaths--either those from the environmental variable classpath or those from the command line list which preempts it. e)A given path component of a -classpath specification includes every directory it contains to be searched. :: b,c,d ?? 120 Given this code fragment: Console c = System.getConsole(); String input = c.readLine("Enter something: "); c.printf("You entered %s\n",input); What is the result of the code? (Choose one answer) a)Compile error--can't find symbol readLine(String). b)Compile error--printf can't interpret '\n'. c)Compiles and runs and prompts 'Enter something' then prints the input. d)Compile error--can't find symbol getConsole(). e)None of the above. :: d ?? 90 Enter the package in which Console is found: :: java.io ?? 30 Given: import java.io.*; public class Konsole { public static void main(String[] args) { Console c = System._______; ______ pWord = c.readPassword("Enter your password: "); c.printf("Your password was " + new String(pWord) + "\n"); String input = c.________("Now type something: "); c.printf("You typed %s\n",input); } } What goes in the blanks? (Choose one answer) a)getConsole(),String,getLine b)getConsole(),String,readLine c)console(),String,readLine d)getConsole(),byte[],getLine e)console(),char[],readLine f)getConsole(),byte[],readInput() :: e ?? 90 Given: interface IOne { public void f(); } interface ITwo extends IOne { public void g(); } public class IFaces { public static void main(String[] args) { ITwo i2 = new ITwo() { public void f() { System.out.println("f!"); } public void g() { System.out.println("g!"); } }; IOne i1 = i2; i1.g(); } } What is the result of this code? (Choose one answer) a)The program compiles, runs without exception, and prints 'f!'. b)Compiler error--interfaces cannot extend other interfaces. c)The program throws a ClassCastException at runtime. d)The program compiles, runs without exception, and prints 'g!'. e)Compiler error--can't find symbol g(). :: e ?? 90 What is true about SortedSet? (x,y,z--no spaces) a)SortedSet is an implementation class of the TreeSet interface. b)SortedSet provides the sorting functionality for the TreeSet class. c)SortedSet provides the 'navigable' functionality for the TreeSet class. d)SortedSet provides the methods higher() and lower(), as well as ceiling() and floor(). e)The 'views' returned by headSet(E toElement), tailSet(E fromElement), and subSet(E fromElement,E toElement) are backed collections of type SortedSet. f)All of the arguments to the 'view'-returning methods are inclusive. :: b,e ?? 120 What is a 'backed collection'? (Choose one answer) a)A collection that keeps a copy in persistent storage in case of data loss due to sudden power failure. b)A collection that maintains double sets of hashcodes for enhanced performance. c)A collection that is linked to the source collection so that any changes to one will be reflected in the other (except for some cases where the changes are outside the range of one of the collections). d)A collection that maintains a clone collection in memory for enhanced performance, allowing for the first() and last() methods. e)None of the above. :: c ?? 90 Given: import java.util.*; public class Navigable { public static void main(String[] args) { TreeSet ts = new TreeSet(); for (int i=0;i<6;i++) ts.add(i); SortedSet ss = ts.headSet(2); //line 1 for (Integer Int:ss) System.out.print(Int + " "); SortedSet ns = ts.subSet(3,true,5,false); //line 2 for (Integer Int:ns) System.out.print(Int + " "); NavigableSet ss2 = ts.tailSet(5); //line 3 for (Integer Int:ss2) System.out.print(Int + " "); } } What is the output of this program? (Choose one answer) a)0 1 3 4 5 b)0 1 2 3 4 5 c)0 1 3 4 5 5 d)2 3 4 5 3 4 0 1 2 3 4 5 e)Compiler error--incompatible types--line 3 f)Compiler error--incompatible types--line 2 and line 3 :: e ?? 180 Given: import java.util.*; public class NavMap { public static void main(String[] args) { TreeMap tm = new TreeMap(); tm.put(0,"zero"); tm.put(1,"one"); tm.put(2,"two"); tm.put(3,"three"); tm.put(4,"four"); tm.put(5,"five"); SortedMap hm = tm.headMap(3); //line 1 for (Integer k:hm.keySet()) System.out.print(hm.get(k) + " "); NavigableMap nm = tm.tailMap(4,true); //line 2 tm.put(7,"eleven"); //line 3 for (Integer k:nm.keySet()) System.out.print(nm.get(k) + " "); } } What is the output of this program? (Choose one answer) a)Compiler error--can't find symbol headMap(Integer) (line 1). b)zero one two four five eleven c)Compiler error--incompatible types (NavigableSet:SortedSet) (line 2). d)zero one two four five e)zero one two Exception (key outside range) (line 3). :: b ?? 120 What is true about NavigableMap? (x,y,z--no spaces) a)It provides the ceilingKey(K key) and floorEntry(K key) methods. b)It is an implementation class of the Map interface. c)It provides the pollFirstEntry() and pollLastEntry() methods. d)It provides the subMap(K fromKey,K toKey) method. e)It extends SortedMap. :: a,c,e ?? 90 Given: class Os { boolean f(int args) { System.out.println("f--super"); return true; } } public class Oloads extends Os { void f(long arg) { System.out.println("f--sub"); } public static void main(String[] args) { Os ol = new Oloads(); ol.f(___); } } What is true about this code? (x,y,z--no spaces) a)If 7 is supplied in the blank, the code compiles and runs without error and prints "f--super". b)If 7 is supplied in the blank, the code compiles and runs without error and prints "f--sub". c)If 7 is supplied in the blank, the code fails to compile. d)If 7l is supplied in the blank, the code compiles and runs without error and prints "f--sub". e)If 7l is supplied in the blank, the code compiles and runs without error and prints "f--super". f)If 7l is supplied in the blank, the code fails to compile. g)None of the above. :: a,f ?? 60 Given: class Ors { void f() throws Exception { Thread.sleep(1000); System.out.println("f--super"); } } class Orides extends Ors { void f() { System.out.println("f--sub"); } public static void main(String[] args) { Ors ors = new Orides(); ors.f(); } } What is the result? (Choose one answer) a)The code compiles and runs without exception and prints "f--sub". b)The code compiles and runs without exception and prints "f--super". c)The code compiles but throws an exception at runtime. d)The code fails to compile. e)The code compiles and runs but has no output. :: d ?? 60 Given: class M { int x = 7; } class N extends M { int x = 8; } class O { M m() { System.out.println("M-version."); return new M(); } } public class Covarrides extends O { N m() { System.out.println("N-version."); return new N(); } public static void main(String[] args) { O o = new Covarrides(); System.out.println(o.m().x); } } What is the result? (Choose one answer) a)Compiler error--m() in Covarrides cannot override m() in O-- incompatible return types. b)Compiler error--ambiguous reference to x. c)The program compiles but throws an exception at runtime. d)The program compiles and runs and prints M-version. 7 e)The program compiles and runs and prints M-version. 8 f)The program compiles and runs and prints N-version. 7 g)The program compiles and runs and prints N-version. 8 :: f ?? 120 Given: import java.util.*; public class PolyGen { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(new Y()); list.add(new Z()); System.out.println(list.get(0) instanceof Y); Z z = list.get(0); } } class X { } class Y extends X { } class Z extends X { } What is the result? a)The program compiles and prints false b)The program compiles but throws a ClassCastException. c)Compiler error--can't find symbol add(Y) [add(Z)]. d)Compiler error--incompatible types (found X--need Z). e)The program compiles and prints true :: d ?? 90 True or False: inner classes can have static fields? (true/false) :: false ?? 30 True or False: abstract methods can take the synchronized modifier? (true/false) :: false ?? 30 Can static (class) methods be private? (choose one answer) a)yes b)no :: a ?? 30 True or False: a package import (utilizing the wildcard syntax) imports ALL package classes and all of their members and static fields? (true/false) :: true ?? 30 Given: public class InnerStatic { { int x = 8; } public static void main(String[] args) { System.out.println("My nested class' x field has a value of "); System.out.println("My inner class has a static field with value"); System.out.println(new InnerStatic().new MyInner().x); } class MyInner { static int x; } } What is the result? (Choose one answer) a)The code compiles and prints 8. b)The code compiles and prints 0. c)The code compiles but throws a ExceptionInInitializerError at runtime. d)There is a compiler error: Inner classes cannot have static declarations. e)None of the above. :: d ?? 60 Given: class PStat { private static void mStat() { System.out.println("This is PStat's private static method."); } } public class PrivStat { public static void main(String[] args) { PStat.mStat(); nStat(); } private static void nStat() { System.out.println("This is my private static method."); } } What is the result? (Choose one answer) a)The code fails to compile because mStat() and nStat() combine the private access modifier with the static modifier. b)The code compiles and prints This is PStat's private static method. This is my private static method. c)The code compiles and prints This is my private static method. d)The code fails to compiles because PrivStat calls PStat's static mStat() method, which is also private. e)The code compiles but throws a ClassMethodException at runtime. :: d ?? 90 Given: File 1-- package com; import MyPkg.ImpTest; public class TestImp { public static void main(String[] args) { System.out.println(ImpTest.x); } } File 2-- package MyPkg; class ImpTest2 {} public class ImpTest extends ImpTest2 { public int x = 7; } Invoke the Java compiler on com/TestImp.java. Assume that there is no default classpath. Use the -cp form of -classpath. The current directory is /java/classes. If the class will not compile given this information, enter 'compile error'. use the -d flag to make sure the compiled classes are built on top of the java/classes directory. Begin your command with 'javac -d'. Use exclusively relative paths as arguments to -d or -cp. The directory structure is: java | ------src | | | -------test1 | | | | | com | | | | | -------TestImp.java | | | -------MyPkg | | | ---------ImpTest.java ------classes :: javac -d . -cp ../src ../src/test1/com/TestImp.java ?? 180 Enter the entity returned by such common NavigableMap methods as ceilingEntry(K key) and higherEntry(K key). Use no other punctuation than is necessary for the name of the entity, then hit : :: Map.Entry ?? 30 Given this code fragment: TreeMap tm = new TreeMap(); [...add entries...] Set> entry = tm._______(); Fill in the blank: :: entrySet ?? 60 Given: import java.util.*; public class UnComparable { public static void main(String[] args) { TreeSet ts = new TreeSet(); ts.add(new Doof("oog")); //line 1 ts.add(new Boof("doogie")); //line 2 ts.add(new Doof("boog")); for (Boof boof:ts) System.out.println(boof); } } class Boof { Boof(String name) { this.name = name; } String name; public String toString() { return name; } } class Doof extends Boof implements Comparable { Doof(String name) { super(name); //line 3 } public int compareTo(Doof d) { return this.name.compareTo(d.name); //line 4 } } What is the result of this code? a)Compiler error at line 1. b)Compiler error at line 2. c)Compiler error in class Doof, line 3. d)Compiler error in class Doof, line 4. e)The code compiles but throws a ClassCastException at runtime. f)The code compiles and prints boog doogie oog g)None of the above. :: e ?? 180 Given: interface Stuff {} class A implements Stuff {} class B {} class C extends A {} class D extends C { public static void main(String[] args) { Stuff s1 = null; B b1 = (B)s1; //line 1 C c1 = (C)s1; //line 2 D d1 = new D(); //line 3 Stuff s2 = (Stuff)b1; //line 4 d1 = (D)s2; //line 5 d1.go(); //line 6 } void go() { System.out.println("go"); } } Enter the line number of the first compile error or exception: :: 6 ?? 120 Enter the name of the List implementation class that provides constant time random access, ordered, unsorted elements, and is unsynchronized: :: ArrayList ?? 30 Given: class Atmet { Atmet(int breaths) { this.breaths = breaths; } int breaths; void breath() { System.out.println("haaaahuuuhhhhhaaaaahuuuuuuhhh"); } } public class Wag extends Atmet { public static void main(String[] args) { Atmet am = new Wag(); am.breath(); } public final breath() { System.out.println("AAAaaaaahhhhhsssszzz...."); } } What is the result of this code? a)The code compiles and prints haaaahuuuhhhhhaaaaahuuuuuuhhh b)Compiler error--breath() in Wag is an illegal override. c)The code compiles and prints AAAaaaaahhhhhsssszzz.... d)Compiler error--can't find symbol constructor Atmet(). e)The code compiles but an exception is thrown at runtime. :: d ?? 120 Given: class X { private int z; private X(int z) { //line 1 this.z = z; } X() { this(7); } //line 2 } public class Y extends X { public static void main(String[] args) { Y y = new Y(); //line 3 System.out.println("z is " + y.z); //line 4 } } What is the result of the code? (Choose one answer) a)The code compiles and prints z is 0 b)The code compiles and prints z is 7 c)Compiler error--line 1. d)Compiler error--line 2. e)Compiler error--line 3. f)Compiler error--line 4. g)An exception is thrown at runtime. :: f ?? 120 Given: import java.util.*; public class RawLists { public static void main(String[] args) { List list = new ArrayList(); list.add("boo"); //line 1 List list2 = new ArrayList(); new RawLists().m1(list2); //line 2 new RawLists().m2(list2); //line 3 } void m1(List list) { System.out.println(list); list.add("dooh"); //line 4 } void m2(List list) { list.add("pooh"); //line 5 } } Which is the first line to generate a warning, and which is the first line to generate a compiler error? (Choose one answer) a)1,2 b)1,3 c)1,1 d)1,4 e)A warning is generated by line 2, but none of the lines cause a compiler error. :: d ?? 120 Given: import java.util.*; enum Cheeks { ROUND,FLAT,FAT } class GenComp implements Comparator { //line 1 public int compare(Buns b1,Buns b2) { return b1.cheeks.ordinal()-b2.cheeks.ordinal(); } } class Buns { Cheeks cheeks; Buns(Cheeks cheeks) { this.cheeks = cheeks; } public String toString() { return cheeks.toString(); } } public class GenComparator { public static void main(String[] args) { Buns b1 = new Buns(Cheeks.FAT); Buns b2 = new Buns(Cheeks.FLAT); Buns b3 = new Buns(Cheeks.FAT); Buns b4 = new Buns(Cheeks.ROUND); Buns[] buns = { b1,b2,b3,b4 }; Arrays.sort(buns,new GenComp()); //line 2 for (Buns booty:buns) System.out.println(booty); } } What is the result of this code? (Choose one answer) a)The code compiles and prints FAT FAT FLAT ROUND b)The code compiles and prints FAT FLAT FAT ROUND c)The code compiles and prints ROUND FLAT FAT FAT d)The code compiles but throws an exception at runtime. e)Compiler error--line 1. f)Compiler error--line 2. :: f ?? 180 Given: public class InitOrder { int x = 7; { System.out.print(x + " "); } { System.out.print(y + " "); } int y = 8; public static void main(String[] args) { InitOrder io = new InitOrder(); System.out.println(io.x + " " + io.y); } } What is the result? (Choose one answer) a)The code compiles and prints 7 8 7 8 b)Compiler error. c)The code compiles but throws an exception at runtime. d)The code compiles and prints 0 8 7 8 e)The code compiles and prints 0 0 7 8 :: b ?? 120 Given: public class TestInstance { public static void main(String[] args) { method1(); method2(); } static void method1() { int x; System.out.println("boo"); x = 7; int y = 27%-x; System.out.println("x and y are " + x + ", " + y); } static void method2() { int x; for (int y=0;y<10;y++) { if (y<5) { x = y; } else { System.out.print(x); } System.out.print("*"); } } } What is the result? (Choose one answer) a)The code compiles and runs and prints x and y are 7, 6 *****44444 b)The code compiles and runs and prints x and y are 7, -6 *****44444 c)The code compiles but throws an exception at runtime. d)Compiler error--variable x might not have been initialized. e)Compiler error--illegal operand 27%-x. :: d ?? 120 Given this code fragment: HashSet hs = new HashSet(); hs.add("one"); hs.add("two"); hs.add("one"); for (String s:hs) System.out.print(s+" "); What is the result? a)The code compiles and runs and prints one two one b)The code compiles but throws a ClassCastException at runtime. c)The code compiles but throws an Error at runtime. d)The code compiles and runs and prints one two e)Compiler error--duplicate entry. :: d ?? 90 Given this code fragment: double d = 36.36; System.out.printf("%5.0f%%%n%s%n",d,d); What prints? a)Compiler error--use of s is incompatible with double variable d. b)Compiler error--four variables specified, only two supplied. c)Compiler error--width specification exceeds size of variable. d)Compiles and prints 5.0% 36.36 e)Compiles and prints 36% 36.36 f)Compiles and prints 0036%[\n] g)Compiles but throws an exception at runtime. :: e ?? 120 Given: public class AssertChange { public static void main(String[] args) { int x = 7; assert --x>8:"x is less than 8."; System.out.println("done."); } } and the inocation java -ea AssertChange What is true? (x,y,z--no spaces) a)The code compiles throws an AssertionError with the message x is less than 8. b)The code compiles and runs and prints done. c)The code represents a proper use of the assertion mechanism. d)The code represents an improper use of the assertion mechanism. e)Compiler error--improperly formed assertion statement. :: a,d ?? 120 True or False: abstract classes can have final methods? (true/false) :: true ?? 30 True or False: abstract methods can use the synchronized modifier. (true/false) :: false ?? 30 Given this code fragment: String s = "newspaper"; System.out.printf("I read the %S",s); What is the result? (Choose one answer) a)The code compiles and prints I read the newspaper b)The code compiles but throws an UnknownFormatConversionException at runtime. c)The code compiles and prints I read the %S. d)The code compiles and prints I read the NEWSPAPER e)Compiler error--can't find symbol S. :: d ?? 90 Given: class Mega {} class Giga extends Mega {} public class GenMeth { public static void main(String[] args) { genMeth(new Mega(),new Giga()); genMeth(new Mega(),new Mega()); } static <_______> void genMeth(X x,Y y) { System.out.println(x.getClass().getSimpleName() + " " + y.getClass().getSimpleName()); } } Complete the code by filling in the blank with the proper declaration of the generic method type. Enter only what should go within the <>'s, not the brackets as well. Use no unneccessary spaces: :: X,Y extends X ?? 120 Given: public class FoRef { int x = getY(); int y = 3; int getY() { return y; } public static void main(String[] args) { System.out.println("x is " + new FoRef().x); } } What is the result of this code? (Choose one answer) a)Compiler error--illegal forward reference. b)The code compiles and runs and prints x is 0 c)Compiler error--cannot find symbol 'y'. d)The code compiles and runs and prints x is 3 e)The code compiles but throws an exception at runtime. :: b ?? 120 Given: class Boob { private String nipples; public String getNipples() { return nipples; } public void setNipples(String nipples) { this.nipples = nipples; } } public class FinalObj { public static void main(String[] args) { final Boob boob = new Boob(); final Boob boob1; boob.setNipples("inverted"); boob1 = boob; //line 1 boob1.setNipples("perky"); boob = boob1; //line 2 } } What is the outcome of this code? (Choose one answer) a)Compiler error--cannot find symbol setNipples(String). b)The program compiles but throws an exception at runtime. c)Compiler error--cannot assign a value to final variable boob1 (line 1). d)The program compiles and runs and prints inverted e)Compiler error--cannot assign a value to final variable boob (line 2). :: e ?? 120 Given this code fragment double d = 0.0/0.0; double dubble = 7.0; System.out.print((d==dubble) + " "); System.out.print((d!=dubble) + " "); dubble = Math.sqrt(-1); System.out.println(d==dubble); What is the result? a)The code compiles but throws an ArithmeticException at runtime. b)The code compiles and prints false true true c)Compiler error--NaN may not be an operand of ==. d)The code compiles and prints false false true e)The code compiles and prints false true false f)None of the above. :: e ?? 90 True or False: class B which extends A successfully overrides Integer m() { return 3; } in A with int m() { return 3; }? (true/false) :: false ?? 60 Given: package test3; import java.io.*; class Vehicle { int color; String size; public Vehicle(int c,String s) { color = c; size = s; } } class Bicycle extends Vehicle implements Serializable { String style; public Bicycle(String st,int c,String s) { super(c,s); style = st; } } public class ObjGraph { public static void main(String[] args) { Bicycle bike = new Bicycle("ten-speed",3,"medium"); Bicycle bike2 = null; try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("mybike")); oos.writeObject(bike); }catch(IOException ioe) { System.err.println("IO exception."); System.exit(0); } try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("mybike")); bike2 = (Bicycle)ois.readObject(); }catch(InvalidClassException ice) { System.err.println("Invalid class exception."); System.exit(0); } catch(Exception e) { System.err.println("Exception."); System.exit(0); } System.out.println("Bike read from storage is of the " + bike2.style + " style."); } } What is the result of running this code? (Choose one answer) a)The code compiles and prints "IO exception." and exits. b)The code compiles and prints "Invalid class exception." and exits. c)The code compiles and prints "Exception." and exits. d)Compiler error--Vehicle does not implement Serializable. e)The code compiles and runs and prints Bike read from storage is of the ten-speed style. :: b ?? 180 Given: public class Marxist { static String Nationality = "German"; public static void main(String[] args) { System.out.println("Marx was the first " + new Marxist().getClass().getSimpleName()); System.out.println("Marx was a " + this.Nationality); } } Does this code compile? (Choose one answer) a)yes b)no :: b ?? 60 Is the following import legal? ('yes' or 'no') import java.io; :: no ?? 30 Given: import java.text.*; import java.util.*; public class GermanNumber { public static void main(String[] args) { Number n = null; Locale german = new Locale("de","DE"); NumberFormat nf = NumberFormat.getInstance(german); String input = args.length > 0?args[0]:"7"; assert input.charAt(0) >=48 && input.charAt(0) <= 58: "Invalid string."; try { n = nf.parse(input); }catch(ParseException pe) { System.err.println("Bad number."); } String germanNum = nf.format(n); System.out.println(germanNum); } } What is true about this class? (x,y,z--no spaces) a)It compiles. b)It doesn't compile. c)It runs if a string beginning with an integer char is supplied as a parameter in the invocation. d)It represents proper use of the assertion mechanism. e)It will run successfully even if no parameter is supplied. :: a,c,e ?? 180 Given the code fragment: ______ x = Long.__Value(); How many different ways could the blanks be filled so that a valid 32-bit number is declared, and initialized legally? (Enter a number between 0 and 9) :: 4 ?? 180 Given the code fragment: StringBuffer sb = "axis"; //line 1 sb.concat(" of evil"); //line 2 System.out.println(sb); //line 3 What is true? (x,y,z--no spaces) a)The code compiles and prints axis of evil b)The code compiles but throws an exception at runtime. c)The code doesn't compile due to an error on line 1. d)The code doesn't compile due to an error on line 2. e)The code doesn't compile due to an error on line 3. :: c,d ?? 90 Given: import java.util.*; public class BiSearch { public static void main(String[] args) { List list = new ArrayList(); list.add("alpha"); list.add(" 1l"); list.add(" Law"); list.add("beta"); list.add("wiccan"); System.out.println(Collections.binarySearch(list,"baba")); } } What is the result of running this code? (Choose one answer) a)Compiler error--cannot find symbol binarySearch(List,String) b)The code compiles and runs but the return value of binarySearch is not predictable according to an accepted rule as it is "undefined." c)The code compiles but throws an exception at runtime. d)The code compiles and runs and prints 1, assuming that the jvm sorts spaces before numbers. e)The code compiles and runs and prints -2. :: b ?? 120 Given this code fragment: Set set = new HashSet(); boolean b = true; set.add(b); Does the code compile? (yes/no): :: no ?? 30 Given this code fragment: List iList = new ArrayList(); for (int x=0;x<5;x++) iList.add(x); List list = iList; for (___ x: list) System.out.println(x.intValue()); fill in the blank with an entry that will allow the code to compile: :: Number ?? 90 Given this file: interface Functions { void printIt(); } interface Methods extends Functions { } class Calculator implements Functions { Functions m1() { Functions f = new Calculator(); //line 1 return f; } public void printIt() { System.out.println("Calculator."); } } class Adjustor implements Methods { Methods m1() { Adjustor adj = new Adjustor(); return adj; //line 2 } public void printIt() { System.out.println("Adjustor."); } } public class IfaceReturn { public static void main(String[] args) { Calculator c = new Calculator(); Functions function = c.m1(); function.printIt(); } } What is the result? (Choose one answer) a)The program compiles but throws an exception at runtime. b)The program compiles and runs and prints Adjustor. c)Compiler error--line 1. d)The program compiles and runs and prints Calculator. e)Compiler error--line 2. :: d ?? 180 Given: public class Racer { public static void main(String[] args) { int [] ints = new int[3]; //line 1 assert ints[2] == 0: "Good."; //line 2 for (int x=0;x<5;x++) ints[x] = x; } } and the invocation, should the code compile, of java -ea Racer What is the result? (Choose one answer) a)The code compiles but an exception is thrown at runtime. b)The code compiles but an AssertionError is thrown with the message Good. c)Compiler error--line 1. d)Compiler error--line 2. e)None of the above. :: a ?? 120 Enter the signature of the finalize method using this format-- public int compareTo(Object o) { and do not include any unecessary spacing: :: protected void finalize() throws Throwable { ?? 60 Given this code fragment: List list = new Vector(); list.add("bobblehead"); System.out.println((list.toArray())[0] instanceof String); What prints? (Choose one answer) a)true b)false c)Compiler error. :: a ?? 90 Given the code fragment: boolean b = Pattern.matches("\\d*","abc"); System.out.println(b); Enter the output bellow: (output) :: false ?? 30 Given the files: package x1; public interface STATS { int RATING = 100; } --- package x2 import static x1.STATS.*; public class DoIt { public static void main(String[] args) { System.out.println("My stats are " + RATING); } } What is the result? a)Compile error--import static not supported for interfaces. b)Compiles but an exception is thrown at runtime. c)Compiles and runs and prints My stats are 0 d)Compiles and runs and prints My stats are 100 e)Compile error--DoIt does not implement test2.STATS. f)None of the above. :: d ?? 90 Given: class A { } class B extends A { } public class Test { public static void main(String[] args) { new Test().m(new A(),new B()); new Test().m(new B(),new B()); } void m(A a,B b) { System.out.println("overload 1"); } void m(B b,A a) { System.out.println("overload 2"); } } What is true about this code? (x,y,z--no spaces) a)There are no syntax errors. b)The code will compile and run and print overload 1 overload 2 c)The first version of m() will not compile. d)The second version of m() will not compile. e)Neither version of m() will compile. f)There is an ambiguous method call error. g)The program will compile and run and print overload 1 then throw a runtime exception. :: a,d,f ?? 180 Given: class Foozie { static int instances; int num; { if (instances++ == 0) { Foozie fz1 = new Foozie(null,instances); } } Foozie fz; Foozie(Foozie fz,int num) { this.fz = fz; this.num = num; System.out.println("Foozie" + num + " created."); instances++; } protected void finalize() { System.out.println("finalize called on " + this.num); } public static void main(String[] args) { Foozie fz0 = new Foozie(null,instances); Foozie fz3 = fz0.fz; fz0.fz = new Foozie(null,instances); fz0.fz = fz3; System.gc(); //line 1 } } How many objects are eligible for garbage collection at line 1? (Choose one answer) a)0 b)1 c)2 d)3 e)4 :: c ?? 240 Given: public class TrashIt { class TI { } TI ti; TrashIt(TI ti) { this.ti = ti; } TrashIt() { } public static void main(String[] args) { TrashIt ti1 = new TrashIt(); TrashIt.TI teeaye = ti1.new TI(); TrashIt ti2 = new TrashIt(teeaye); ti1.ti = ti1.new TI(); ti2.ti = ti1.ti; TrashIt ti3 = ti1; ti1.ti = null; TrashIt ti4 = new TrashIt(null); ti2 = null; System.gc(); } } How many object are eligable for garbage collection at the gc() call? (Choose one answer) a)0 b)1 c)2 d)3 e)4 :: c ?? 240 Given: public class BB { BB bb; void doIt(BB beebee) { BB bB = new BB(); bB.bb = null; } public static void main(String[] args) { BB bb1 = new BB(); for (int x = 0;x<2;x++) { BB bb = new BB(); bb1.doIt(bb); } bb1.bb = new BB(); BB bb2 = bb1.bb; bb1.doIt(new BB()); bb1 = null; System.gc(); } } How many objects are eligible for garbage collection when System.gc() is called? a)1 b)3 c)5 d)7 e)9 f)None of the above. :: d ?? 240 Given: public class Tanager { Tanager t; Tanager(Tanager t) { this.t = t; System.out.println("Tanager created."); } Tanager() { } public static void main(String[] args) { Tanager t1 = new Tanager().t; Tanager t2 = new Tanager(t1); Tanager t3 = new Tanager(t2); t2.t = t3; t3.t = t1; t3 = null; System.gc(); } } How many objects are eligible for garbage collection when System.gc() is called? a)0 b)1 c)2 d)3 e)4 :: b ?? 240 Given: public class Ambiguous { public static void main(String[] args) { new Ambiguous().go(_____); } void go(Integer...i) { System.out.println("Wrapper."); } void go(int...i) { System.out.println("primitive."); } } What is true about this class? (x,y,z--no spaces) a)If an int or a Integer is put in the blank, the code compiles. b)If an int array or an Integer array is put in the blank, the code compiles. c)The code cannot compile no matter what is put in the blank. d)If an int or an Integer is put in the blank, the code will compile but there will be an exception at runtime. e)If an int or an Integer is put in the blank, the code doesn't compile. :: b,e ?? 120 Given: public class Selection { public static void main(String[] args) { doIt(new Boolean("tRuE"),3l,new Character('1')); doIt(false,new Double(3.0),'1'); } static void doIt(Boolean b,Double d,Character c) { System.out.println("Wrapper types."); } static void doIt(boolean b,double d,char c) { System.out.println("Primitive types."); } } What is the result of this code? (Choose one answer) a)The code runs and prints Wrapper types. Wrapper types. b)The code runs and prints Primitive types. Wrapper types. c)The code runs and prints Primitive types. Primitive types. d)The code fails to compile. e)The code compiles but throws an exception at runtime. :: d ?? 120 Given: class BoatHouse { enum Boats { DINGHY(8),SKIFF(10),CORACLE(6); int length; Boats(int length) { this.length = length; } public String toString() { return name() + " (" + this.length + "ft)"; } } } public class DoBoats { Boats boat; public static void main(String[] args) { for (_________ boat:__________) System.out.println(boat); } } Fill in each of the two blanks with the code required to iterate over the contents of the enum. Separate the two entries with one comma and no spaces--ie First.answer,Second answer then hit to submit your answers: :: BoatHouse.Boats,BoatHouse.Boats.values() ?? 180 Given: interface XZ { int x = 7; } class Headlight implements XZ { public int z = 8; } public class TailFin extends Headlight { public static void main(String[] args) { new TailFin().go(); } void go() { System.out.println("" + this.x + this.z); } } What is the result of running this code? (Choose one answer) a)The code compiles and runs and prints 00 b)The code compiles and runs and prints 15 c)Compiler error: keyword 'this' cannot refer to class fields. d)The code compiles but throws an exception at runtime. e)The code compiles and runs and prints 78 :: e ?? 120 Can abstract methods be private? (Choose one answer) a)yes b)no :: b ?? 30 Can enums have abstract methods? (Choose one answer) a)yes b)no :: a ?? 30 Can a final class have abstract methods? (Choose one answer) a)yes b)no :: b ?? 30 Can abstract classes have final methods? (Choose one answer) a)yes b)no :: a ?? 30 Given: interface X1 { public static final x = 7; } interface X2 extends X1 { public static final z = ______; } What can go in the blank to allow z to obtain x's value? (x,y,z--no spaces) a)super.x b)x c)this.x d)X1.x e)none of the above :: a,d ?? 90 Can abstract classes have static methods? (Choose one answer) a)yes b)no :: a ?? 30 Given this method code: int x = 3; double d = 0.0/0.0; double dd = 0.0/0.0; Object o1 = null; System.out.println(d==x + ", " + d==dd + ", " + d!=dd); System.out.println(o1==null + ", " + o1==new Integer() + ", " + o1!=null); What prints? (Choose one answer) a)false, false, true true, false, false b)Compile error--null may not be an operand of '=='. c)Program compiles but throws an exception at runtime. d)false, true, false true, false, false e)Compile error--NaN may not be an operand of '=='. :: a ?? 120