SUN公司SCJP题库
SCJP题库 带达内考点分析②

Module2-类、接口以及枚举一、选择题:Question1Given:11.public interface Status{12./*insert code here*/int MY_V ALUE=10;13.}Which three are valid on line12?(Choose three.)A.finalB.staticC.nativeD.publicE.privateF.abstractG.protectedQuestion2Given:10.class Foo{11.static void alpha(){/*more code here*/}12.void beta(){/*more code here*/}13.}Which two are true?(Choose two.)A.Foo.beta()is a valid invocation of beta().B.Foo.alpha()is a valid invocation of alpha().C.Method beta()can directly call method alpha().D.Method alpha()can directly call method beta().Question3Click the Exhibit button.11.class Payload{12.private int weight;13.public Payload(int wt){weight=wt;}14.public Payload(){}15.public void setWeight(mt w){weight=w;}16.public String toString{return Integer.toString(weight);}17.}18.19.public class TestPayload{20.static void changePayload(Payload p){21./*insert code here*/22.}23.24.public static void main(String[]args){25.Payload p=new Payload();26.p.setWeight(1024);27.changePayload(p);28.System.out.println("The value of p is"+p);29.}30.}Which statement,placed at line21,causes the code to print“The value of p is420.”?A.p.setWeight(420);B.p.changePayload(420);C.p=new Payload(420);D.Payload.setWeight(420);E.p=Payload.setWeight(420);F.p=new Payload();p.setWeight(420);Question4Click the Exhibit button.1.public class Item{2.private String desc;3.public String getDescription(){return desc;}4.public void setDescription(String d){desc=d;}5.6.public static void modifyDesc(Item item,String desc){7.item=new Item();8.item.setDescription(desc);9.}10.public static void main(String[]args){11.Item it=new Item();12.it.setDescription("Gobstopper");13.Item it2=new Item();14.it2.setDescription("Fizzylifting");15.modifyDesc(it,"Scrumdiddlyumptious");16.System.out.println(it.getDescription());17.System.out.println(it2.getDescription());18.}19.}What is the outcome of the code?pilation fails.B.GobstopperFizzyliftingC.GobstopperScrumdiddlyumptiousD.ScrumdiddlyumptiousFizzylifltngE.ScrumdiddlyumptiousScrumdiddlyumptiousQuestion5Given:11.public class ItemTest{12.private final in t id;13.public ItemTest(int id){this.id=id;}14.public void updateId(int newId){id=newId;}15.16.public static void main(String[]args){17.ItemTest fa=new ItemTest(42);18.fa.updateId(69);19.System.out.println(fa.id);20.}21.}What is the result?pilation fails.B.An exception is thrown at runtime.C.The attribute id in the Item object remains unchanged.D.The attribute id in the Item object is modified to the new value.E.A new Item object is created with the preferred value in the id attribute.Question6Click the Exhibit button.10.class Inner{11.private int x;12.public void setX(int x){this.x=x;}13.public int getX(){return x;}14.}15.16.class Outer{17.private Inner y;18.public void setY(Inner y){this.y=y;}19.public Inner getY(){return y;}20.}21.22.public class Gamma{23.public static void main(String[]args){24.Outer o=new Outer();25.Inner i=new Inner();26.int n=10;27.i.setX(n);28.o.setY(i);29.//insert code here30.System.out.println(o.getY().getX());31.}32.}Which three code fragments,added individually at line29,produce the output100?(Choose three.)A.n=100;B.i.setX(100);C.o.getY().setX(100);D.i=new Inner();i.setX(100);E.o.setY(i);i=new Inner();i.setX(100);F.i=new Inner();i.setX(100);o.setY(i);Question7Click the Exhibit button.10.class Foo{11.private int x;12.public Foo(int x){this.x=x;}13.public void setX(int x){this.x=x;}14.public int getX(){return x;}15.}16.17.public class Gamma{18.19.static Foo fooBar(Foo foo){20.foo=new Foo(100);21.return foo;22.}23.24.public static void main(String[]args){25.Foo foo=new Foo(300);26.System.out.print(foo.getX()+"-");27.28.Foo fooFoo=fooBar(foo);29.System.out.print(foo.getX()+"-");30.System.out.print(fooFoo.getX()+"-");31.32.foo=fooBar(fooFoo);33.System.out.print(foo.getX()+"-");34.System.out.prmt(fooFoo.getX());35.}36.}What is the output of this program?A.300-100-100-100-100B.300-300-100-100-100C.300-300-300-100-100D.300-300-300-300-100Question8Given:1.interface DoStuff2{2.float getRange(int low,int high);}3.4.interface DoMore{5.float getAvg(int a,int b,int c);}6.7.abstract class DoAbstract implements DoStuff2,DoMore{} 8.9.class DoStuff implements DoStuff2{10.public float getRange(int x,int y){return3.14f;}}11.12.interface DoAll extends DoMore{13.float getAvg(int a,int b,int c,int d);}What is the result?A.The file will compile without error.pilation fails.Only line7contains an error.pilation fails.Only line12contains an error.pilation fails.Only line13contains an error.pilation fails.Only lines7and12contain errors.pilation fails.Only lines7and13contain errors.pilation fails.Lines7,12,and13contain errors. Question9Click the Exhibit button.1.public class A{2.3.private int counter=0;4.5.public static int getInstanceCount(){6.return counter;7.}8.9.public A(){10.counter++;11.}12.13.}Given this code from Class B:25.A a1=new A();26.A a2=new A();27.A a3=new A();28.System.out.printIn(A.getInstanceCount());What is the result?pilation of class A fails.B.Line28prints the value3to System.out.C.Line28prints the value1to System.out.D.A runtime error occurs when line25executes.pilation fails because of an error on line28.Question10Given:1.public class A{2.public void doit(){3.}4.public String doit(){5.return“a”;6.}7.public double doit(int x){8.return1.0;9.}10.}What is the result?A.An exception is thrown at runtime.pilation fails because of an error in line7.pilation fails because of an error in line4.pilation succeeds and no runtime errors with class A occur. Question11Given:10.class Line{11.public static class Point{}12.}13.14.class Triangle{15.//insert code here16.}Which code,inserted at line15,creates an instance of the Point class defined in Line?A.Point p=new Point();B.Line.Point p=new Line.Point();C.The Point class cannot be instatiated at line15.D.Line1=new Line();1.Point p=new1.Point();Question12Click the Exhibit button.10.interface Foo{11.int bar();12.}13.14.public class Beta{15.16.class A implements Foo{17.public int bar(){return1;}18.}19.20.public int fubar(Foo foo){return foo.bar();}21.22.public void testFoo(){23.24.class A implements Foo{25.public int bar(){return2;}26.}27.28.System.out.println(fubar(new A()));29.}30.31.public static void main(String[]argv){32.new Beta().testFoo();33.}34.}Which three statements are true?(Choose three.)pilation fails.B.The code compiles and the output is2.C.If lines16,17and18were removed,compilation would fail.D.If lines24,25and26were removed,compilation would fail.E.If lines16,17and18were removed,the code would compile and the output would be2.F.If lines24,25and26were removed,the code would compile and the output would be1.Question13Given:1.public interface A{2.String DEFAULT_GREETING=“Hello World”;3.public void method1();4.}A programmer wants to create an interface calledB that has A as its parent.Which interface declaration is correct?A.public interface B extends A{}B.public interface B implements A{}C.public interface B instanceOf A{}D.public interface B inheritsFrom A{}Question14Given:1.class TestA{2.public void start(){System.out.println(”TestA”);}3.}4.public class TestB extends TestA{5.public void start(){System.out.println(”TestB”);}6.public static void main(String[]args){7.((TestA)new TestB()).start();8.}9.}What is the result?A.TestAB.TestBpilation fails.D.An exception is thrown at runtime.Question15Given:11.public abstract class Shape{12.int x;13.int y;14.public abstract void draw();15.public void setAnchor(int x,int y){16.this.x=x;17.this.y=y;18.}19.}and a class Circle that extends and fully implements the Shape class. Which is correct?A.Shape s=new Shape();s.setAnchor(10,10);s.draw();B.Circle c=new Shape();c.setAnchor(10,10);c.draw();C.Shape s=new Circle();s.setAnchor(10,10);s.draw();D.Shape s=new Circle();s->setAnchor(10,10);s->draw();E.Circle c=new Circle();c.Shape.setAnchor(10,10);c.Shape.draw();Question16Given:10.abstract public class Employee{11.protected abstract double getSalesAmount();12.public double getCommision(){13.return getSalesAmount()*0.15;14.}15.}16.class Sales extends Employee{17.//insert method here18.}Which two methods,inserted independently at line17,correctly complete the Sales class?(Choose two.)A.double getSalesAmount(){return1230.45;}B.public double getSalesAmount(){return1230.45;}C.private double getSalesAmount(){return1230.45;}D.protected double getSalesAmount(){return1230.45;} Question17Given:10.interface Data{public void load();}11.abstract class Info{public abstract void load();} Which class correctly uses the Data interface and Info class?A.public class Employee extends Info implements Data{ public void load(){/*do something*/}}B.public class Employee implements Info extends Data{ public void load(){/*do something*/}}C.public class Employee extends Info implements Data{ public void load(){/*do something*/}public void Info.load(){/*do something*/}}D.public class Employee implements Info extends Data{ public void Data.load(){/*d something*/}public void load(){/*do something*/}}E.public class Employee implements Info extends Data{ public void load(){/*do something*/}public void Info.load(){/*do something*/}}F.public class Employee extends Info implements Data{ public void Data.load(){/*do something*/}public void Info.load(){/*do something*/}}Question18Given:11.public abstract class Shape{12.private int x;13.private int y;14.public abstract void draw();15.public void setAnchor(int x,int y){16.this.x=x;17.this.y=y;18.}19.}Which two classes use the Shape class correctly?(Choose two.)A.public class Circle implements Shape{private int radius;}B.public abstract class Circle extends Shape{private int radius;}C.public class Circle extends Shape{private int radius;public void draw();}D.public abstract class Circle implements Shape{private int radius;public void draw();}E.public class Circle extends Shape{private int radius;public void draw(){/*code here*/}}F.public abstract class Circle implements Shape{private int radius;public void draw(){/code here*/}}Question19Which two classes correctly implement both the ng.Runnable and the ng.Clonable interfaces?(Choose two.)A.public class Sessionimplements Runnable,Clonable{public void run();public Object clone();}B.public class Sessionextends Runnable,Clonable{public void run(){/do something*/}public Object clone(){/make a copy*/}}C.public class Sessionimplements Runnable,Clonable{public void run(){/do something*/}public Object clone(){/*make a copy*/}}D.public abstract class Sessionimplements Runnable,Clonable{public void run(){/do something*/}public Object clone(){/*make a copy*/}}E.public class Sessionimplements Runnable,implements Clonable{public void run(){/do something*/}public Object clone(){/make a copy*/}}Question20Given:10.class One{11.public One(){System.out.print(1);}12.}13.class Two extends One{14.public Two(){System.out.print(2);}15.}16.class Three extends Two{17.public Three(){System.out.print(3);}18.}19.public class Numbers{20.public static void main(String[]argv){new Three();}21.}What is the result when this code is executed?A.1B.3D.321E.The code rims with no output.Question21Given classes defined in two different files:1.package packageA;2.public class Message{3.String getText(){return“text”;}4.}and:1.package packageB;2.public class XMLMessage extends packageA.Message{3.String getText(){return“<msg>text</msg>”;}4.public static void main(String[]args){5.System.out.println(new XMLMessage().getText());6.}7.}What is the result of executing XMLMessage.main?A.textB.<msg>text</msg>C.An exception is thrown at runtime.pilation fails because of an error in line2of XMLMessage.pilation fails because of an error in line3of XMLMessage. Question22Given:11.interface DeclareStuff{12.public static final int EASY=3;13.void doStuff(int t);}14.public class TestDeclare implements DeclareStuff{15.public static void main(String[]args){16.int x=5;17.new TestDeclare().doStuff(++x);18.}19.void doStuff(int s){20.s+=EASY+++s;21.System.out.println("s"+s);22.}23.}What is the result?A.s14C.s10pilation fails.E.An exception is thrown at runtime.Question2341.Given:10.class One{11.public One foo(){return this;}12.}13.class Two extends One{14.public One foo(){return this;}15.}16.class Three extends Two{17.//insert method here18.}Which two methods,inserted individually,correctly complete the Three class?(Choose two.)A.public void foo(){}B.public int foo(){return3;}C.public Two foo(){return this;}D.public One foo(){return this;}E.public Object foo(){return this;}Question24Given:10.class One{11.void foo(){}12.}13.class Two extends One{14.//insert method here15.}Which three methods,inserted individually at line14,will correctly complete class Two?(Choose three.)A.int foo(){/*more code here*/}B.void foo(){/*more code here*/}C.public void foo(){/*more code here*/}D.private void foo(){/*more code here*/}E.protected void foo(){/*more code here*/}Question25Click the Exhibit button.1.public interface A{2.public void doSomething(String thing);3.}1.public class AImpl implements A{2.public void doSomething(String msg){}3.}1.public class B{2.public A doit(){3.//more code here4.}5.6.public String execute(){7.//more code here8.}9.}1.public class C extends B{2.public AImpl doit(){3.//more code here4.}5.6.public Object execute(){7.//more code here8.}9.}Which statement is true about the classes and interfaces in the exhibit?pilation will succeed for all classes and interfaces.pilation of class C will fail because of an error in line2.pilation of class C will fail because of an error in line6.pilation of class AImpl will fail because of an error in line2. Question26Click the Exhibit button.11.class Person{12.String name="No name";13.public Person(String nm){name=nm;}14.}15.16.class Employee extends Person{17.String empID=“0000”;18.public Employee(String id){empID=id;}19.}20.21.public class EmployeeTest{22.public static void main(String[]args){23.Employee e=new Employee(”4321”);24.System.out.println(e.empID);25.}26.}What is the result?A.4321B.0000C.An exception is thrown at runtime.pilation fails because of an error in line18.Question27Given:1.public class Plant{2.private String name;3.public Plant(String name){=name;}4.public String getName(){return name;}5.}1.public class Tree extends Plant{2.public void growFruit(){}3.public void dropLeaves(){}4.}Which is true?A.The code will compile without changes.B.The code will compile if public Tree(){Plant();}is added to the Tree class.C.The code will compile if public Plant(){Tree();}is added to the Plant class.D.The code will compile if public Plant(){this(”fern”);}is added to the Plant class.E.The code will compile if public Plant(){Plant(”fern”);}is added to the Plant class.Question28Click the Exhibit button.11.public class Bootchy{12.int bootch;13.String snootch;14.15.public Bootchy(){16.this(”snootchy”);17.System.out.print(”first“);18.}19.20.public Bootchy(String snootch){21.this(420,"snootchy");22.System.out.print("second");23.}24.25.public Bootchy(int bootch,String snootch){26.this.bootch=bootch;27.this.snootch=snootch;28.System.out.print("third");29.}30.31.public static void main(String[]args){32.Bootchy b=new Bootchy();33.System.out.print(b.snootch+""+b.bootch);34.}35.}What is the result?A.snootchy420third second firstB.snootchy420first second thirdC.first second third snootchy420D.third second first siiootchy420E.third first second snootchy420F.first second first third snootchy420 Question29Given:1.interface TestA{String toString();}2.public class Test{3.public static void main(String[]args){4.System.out.println(new TestA(){5.public String toString(){return"test";}6.});7.}8.}What is the result?A.testB.nullC.An exception is thrown at runtime.pilation fails because of an error in line1.pilation fails because of an error in line4.pilation fails because of an error in line5.Question30Given:10.interface Foo{int bar();}11.public class Sprite{12.public int fubar(Foo foo){return foo.bar();}13.public void testFoo(){14.fubar(15.//insert code here16.);17.}18.}Which code,inserted at line15,allows the class Sprite to compile?A.Foo{public int bar(){return1;}}B.new Foo{public int bar(){return1;}}C.new Foo(){public int bar(){return1;}}D.new class Foo{public int bar(){return1;}}Question31Given:10.class Line{11.public class Point{public int x,y;}12.public Point getPoint(){return new Point();}13.}14.class Triangle{15.public Triangle(){16.//insert code here17.}18.}Which code,inserted at line16,correctly retrieves a local instance of a Point object?A.Point p=Line.getPoint();B.Line.Point p=Line.getPoint();C.Point p=(new Line()).getPoint();D.Line.Point p=(new Line()).getPoint();Question32A JavaBeans component has the following field:11.private boolean enabled;Which two pairs of method declarations follow the JavaBeans standard for accessing this field?(Choose two.)A.public void setEnabled(boolean enabled)public boolean getEnabled()B.public void setEnabled(boolean enabled)public void isEnabled()C.public void setEnabled(boolean enabled)public boolean isEnabled()D.public boolean setEnabled(boolean enabled)public boolean getEnabled()Question33A programmer is designing a class to encapsulate the information about an inventory item.A JavaBeans component is needed todo this.The Inventoryltem class has private instance variables to store the item information:10.private int itemId;11.private String name;12.private String description;Which method signature follows the JavaBeans naming standards for modifying the itemld instance variable?A.itemID(int itemId)B.update(int itemId)C.setItemId(int itemId)D.mutateItemId(int itemId)E.updateItemID(int itemId)Question34Given:10.class Nav{11.public enum Direction{NORTH,SOUTH,EAST,WEST}12.}13.public class Sprite{14.//insert code here15.}Which code,inserted at line14,allows the Sprite class to compile?A.Direction d=NORTH;B.Nav.Direction d=NORTH;C.Direction d=Direction.NORTH;D.Nav.Direction d=Nav.Direction.NORTH;Question35Given:1.package sun.scjp;2.public enum Color{RED,GREEN,BLUE}1.package sun.beta;2.//insert code here3.public class Beta{4.Color g=GREEN;5.public static void main(String[]argv)6.{System.out.println(GREEN);}7.}The class Beta and the enum Color are in different packages. Which two code fragments,inserted individually at line2of the Beta declaration,will allow this code to compile?(Choose two.)A.import sun.scjp.Color.*;B.import static sun.scjp.Color.*;C.import sun.scjp.Color;import static sun.scjp.Color.*;D.import sun.scjp.*;import static sun.scjp.Color.*;E.import sun.scjp.Color;import static sun.scjp.Color.GREEN; Question36Given:11.public class Ball{12.public enum Color{RED,GREEN,BLUE};13.public void foo(){14.//insert code here15.{System.out.println(c);}16.}17.}Which code inserted at line14causes the foo method to print RED, GREEN,and BLUE?A.for(Color c:Color.values())B.for(Color c=RED;c<=BLUE;c++)C.for(Color c;c.hasNext();c.next())D.for(Color c=Color[0];c<=Color[2];c++)E.for(Color c=Color.RED;c<=Color.BLUE;c++)Question37Given:11.public enum Title{12.MR("Mr."),MRS("Mrs."),MS("Ms.");13.private final String title;14.private Title(String t){title=t;}15.public String format(String last,String first){16.return title+""+first+""+last;17.}18.}19.public static void main(String[]args){20.System.out.println(Title.MR.format("Doe","John"));21.}What is the result?A.Mr.John DoeB.An exception is thrown at runtime.pilation fails because of an error in line12.pilation fails because of an error in line15.pilation fails because of an error in line20.Question38Given:10.public class Fabric11.public enum Color{12.RED(0xff0000),GREEN(0x00ff00),BLUE(0x0000ff);13.private final int rgb;14.Color(int rgb){this.rgb=rgb;}15.public int getRGB(){return rgb;}16.};17.public static void main(String[]argv){18.//insert code here19.}20.}Which two code fragments,inserted independently at line18,allow the Fabric class to compile?(Choose two.)A.Color skyColor=BLUE;B.Color treeColor=Color.GREEN;C.Color purple=new Color(0xff00ff);D.if(RED.getRGB()<BLUE.getRGB()){}E.Color purple=Color.BLUE+Color.RED;F.if(Color.RED.ordinal()<Color.BLUE.ordinal()){} Question39Given:11.public class Test{12.public enum Dogs{collie,harrier,shepherd};13.public static void main(String[]args){14.Dogs myDog=Dogs.shepherd;15.switch(myDog){16.case collie:17.System.out.print("collie");18.case default:19.System.out.print("retriever");20.case harrier:21.System.out.print("harrier");22.}23.}24.}What is the result?A.harrierB.shepherdC.retrieverpilation fails.E.retriever harrierF.An exception is thrown at runtime.Question40Given:12.public class Test{13.public enum Dogs{collie,harrier};14.public static void main(String[]args){15.Dogs myDog=Dogs.collie;16.switch(myDog){17.case collie:18.System.out.print("collie");19.case harrier:20.System.out.print("harrier");21.}22.}23.}What is the result?A.collieB.harrierpilation fails.D.collie harrierE.An exception is thrown at runtime.二、拖拽题:Question1:。
35道SCJP考试真题精解

35道SCJP考试真题精解例题1:Choose the three valid identifiers from those listed below.A. IDoLikeTheLongNameClassB. $byteC. constD. _okE. 3_case解答:A, B, D点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。
关键字与保留字不能作为标示符。
选项C中的const是Java的保留字,所以不能作标示符。
选项E中的3_case以数字开头,违反了Java的规则。
例题2:How can you force garbage collection of an object?A. Garbage collection cannot be forcedB. Call System.gc().C. Call System.gc(), passing in a reference to the object to be garbage collected.D. Call Runtime.gc().E. Set all references to the object to new values(null, for example).解答:A点评:在Java中垃圾收集是不能被强迫立即执行的。
调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。
所以选项B、D不正确。
选项C的错误在于,System.gc()方法是不接受参数的。
选项E中的方法可以使对象在下次垃圾收集器运行时被收集。
例题3:以下是引用片段:Consider the following class:1. class Test(int i) {2. void test(int i) {3. System.out.println(“I am an int.”);4. }5. void test(String s) {6. System.out.println(“I am a string.”);7. }8.9. public static void main(String args[]) {10. Test t=new Test();11. char ch=“y”;12. t.test(ch);13. }14. }Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void methods cannot be overridden.B. Line 12 will not compile, because there is no version of test() that rakes a char argument.C. The code will compile but will throw an exception at line 12.D. The code will compile and produce the following output: I am an int.E. The code will compile and produce the following output: I am a String.解答:D点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。
SCJP考题

1.import java.io.*;public class Forest implements Serializable {private Tree tree = new Tree();public static void main(String[] args) {Forest f = new Forest();try {FileOutputStream fs = new FileOutputStream("Forest.ser");ObjectOutputStream os = new FileOutputStream(fs);os.writerObject(f);os.close();} catch(Exception ex) {ex.printStackTrace();}}}class Tree() {}Q: 运行结果是:A: B)在运行过程中抛出一个错误E: 因为class Tree没有被序列化,Forest要序列化的话,它里面包含的类对象都要被序列化2.import java.io.*;public class Foo implements Serializable {public int x,y;public Foo(int x,int y) {this.x = x;this.y = y;}private void writeObject(ObjectOutputStream s) throws IOException {s.writeInt(x);s.writeInt(y);}private void readObject(ObjectInputStream s) throws IOException,ClassNotFoundException {// insert code here 14}}Q: 哪些代码插入第14行,能够让class正确的完成序列化和反序列化?A: D) x = s.readInt(); y = s.readInt();3.String test = "This is a test";String[] tokens = test.split("\s");System.out.println(tokens.length);Q: 给出上面代码,执行结果如何?A: D) 编译出错E: 因为"\s"是个错误的转义字符,正确的只有"\b,\t,\n,\f,\r,\",\',\\"4.Date date = new Date();df.setLocale(Local.Ialy); // 13String s = df.format(date);Q: df是一个DateFormat对象并已经初始化完成,问将“December 14,2000”参与运行是什么结果A: D)在第13行编译出错,DateFormat没有setLocale()方法5.Q: 给定一个集合,里面存放的是路径名的分节,如何用代码实现判断这个路径或文件是否存在A: [String path = "";]for(String dir: directories) {[path = path + File.separator + dir;]}[File file = new File(path,filename);][return file.exists();]E: File.separator表示不区分操作系统的分隔符,exists()方法测试该对象表示的路径或文件是否存在6.Q: 给出下面代码,问运行结果System.out.printf("Pi is %f and E is %b",Math.PI,Math.E);A: Pi is 3.14593 and E is true7. Q: 当比较java.io.BufferedWriter和java.io.FileWriter,下面哪些说法是两者共有的A: E) 写一条线分离的流8.Q: 给出下面代码,如何实现打印出“4247”(2个答案)public class Certkiller3 {public static void main(String[] args) {// insert code hereSystem.out.println(s);}}A: B) StringBuffer s = new StringBuffer("123456789");s.delete(0,3).replace(1,3,"24").delete(4,6);E) StringBuffer s = new StringBuffer("123456789");s.delete(0,3).replace(1,3,).delete(2,5).insert(1,"24");9.Q: 下面关于java.io.Realizable接口说法正确的三项是A: B)一个对象被一个JVM序列化后能被另一个JVM反序列化D)一个被transient修饰的属性不能被序列化和反序列化E)一个能被序列化的对象他的超类不用实现java.io.Serialiation接口10.public class Certkiller {public static void go(short n) {System.out.println("short");}public static void go(short n) {System.out.println("SHORT");}public static void go(long n) {System.out.println("long");}public static void main(String[] args) {short y = 6;int z = 7;go(y);go(z);}}Q: 问执行结果A: C) 编译失败E: go(short n) 方法已经存在11.Q: d是有效的,非空的Date对象,df是有效的,非空的DateFormat对象并被设置为本地格式下面的代码如何输出本地国家名字和当前时间A: B) Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+" "+df.foramt(d));12.public class Certkiller3 implements Runnable {public void run() {System.out.print("running");}public static void main(String[] args) {Thread t = new Thread(new Certkiller3());t.run();t.run();t.start();}}Q: 问执行结果A: 代码执行成功并打印“runningrunningrunning”13.public class Threads1 {int x = 0;public class Runner implements Runnable {public void run() {int current = 0;for(int i = 0; i<4; i++) {current = x;System.out.println(current + ",");x = current + 2;}}}public static void main(String[] args) {new Threads1().go();}public void go() {Runnable r1 = new Runner();new Thread(r1).start();new Thread(r1).start();}}Q: 下面哪两个是可能的运行结果A: A) 0,2,4,4,6,8,10,6C) 0,2,4,6,8,10,12,14E: 多个线程共用一个资源14.void waitForSignal() {Object obj = new Object();synchronized (Thread.currentThread()) {obj.wait();obj.notify();}}Q: 那个说法是正确的A: B) 这段代码会抛出一个IllegalStateExceptionE: IllegalStateException在非法或不适当的时间调用方法时产生的信号15public class TestOne implements Runnable {public static void main(String[] args) throws Exception {Thread t = new Thread(new TestOne());t.start();System.out.println("Started");t.join();System.out.println("Complete");}public void run() {for(int i = 0;i<4;i++) {System.out.println(i);}}}Q: 执行结果A: E) 代码执行成功并打印“Started0123Complete”16.Q: 下面哪两种写法能让doStuff()方法运行在一个线程中A: D) new Thread() {public void run(){doStuff();}}.start();F) new Thread(new Runnable() {public void run(){doStuff();}}.start();17.Q: 下面哪三种写法不会出错A: C) public synchronized void go() {/*code here*/}E) void go() {synchronized(Object.class) {/*code here*/}}F) void go() {synchronized(o) {/*code here*/}}18.class Computation extends Thread {private int num;private boolean isComplete;private int result;public Computation(int num) {this.num = num;}public synchronized void run() {result = num * 2;isComplete = true;notify();}public synchronized int getResult() {while(!isComplete) {try {wait();} catch(InterruptedException e) {}}return result;}public static void main(String[] args) {Computation[] computations = new Computation[4];for(int i = 0; i < computations.length; i++) {computations[i] = new Computation(i);computations[i].start();}for(Computation c : computations)System.out.print(c.getResult() + " ");}}Q: 执行结果A: F) 代码运行并打印“0 2 4 6”19.public class Certkiller {public static void main(String[] args) throws Exception { Thread.sleep(3000);System.out.println("sleep");}}Q: 执行结果A: C)代码正常执行并打印“sleep”20.?Q: 下面说法正确的2个是A: A)继承是一种关系D)实例变量时可以使用创造了一个关系E: is-a 表示类的继承关系has-a表示对象和成员的从属关系he is a people ;he has a head21.package certkiller;class Target {public String name = "hello";}Q: 什么情况下可以直接访问和修改变量nameA: C) 任何在certkiller包下的类E: public是任何类都能访问的,但class Target只能被同包下的类访问22.Q: 下面哪三项是正确的A: B) 一个class X中的protected方法能被任何一个X的子类所重写E) 一个class X中的public static的方法被一个没有明确参照X的子类所调用F) 在class X的子类中存在一个方法,该方法与class X中一个private final方法同名E: 因为private方法是无法被继承的,所以在子类中可以存在同名方法23.Q: 选择填空,区分is-a和has-aA: [Dog] [is-a] AnimalForest [has-a] [Tree]Rectangle [has-a] [Side][Java Book] [is-a] Programming BookE: 狗是一种动物,森林有树,矩形有边,java书籍是一种编程书籍24. ?public class Single {[private] [static] Single instance;[public] [static] Single getInstance() {if(instance == null) instance = create();return instance;}[private] Single() {} // 1.[protected] Single create() {return new Single();} // 2.}Q: 替换两个修饰符来修饰方法让代码编译通过A: 将//1. 处替换为[protected],将//2. 处替换为[static]25.public class SimpleCale {public int value;public void calculate() {value += 7;}}public class MultiCalc extends SimpleCalc {public void calculate() {value -= 3;}public void calculate(int multiplier) {calculate();super.calculate();value *= multiplier;}public staic void main(String[] args) {MultiCalc calculator = new MultiCalc();calculator.calculate(2);System.out.println("Value is: " + calculator.value);}}Q: 执行结果A: A) Value is : 8;26.public class CertkillerCard {private String cardID;private Integer limit;public String ownerName;public void setCardInformation(String cardID,String ownerName,Integer limit) { this.cardID = cardID;this.ownerName = ownerName;this.limit = limit;}}Q: 下面说法哪个是对的A: C) ownerName改变了封装(翻译不准确)E: 这道题目主要考察类的封装特性,ownerName属性是公共的27.class Animal {public String noise() {return "peep";}}class Dog extends Animal {public String noise() {return "back";}}class Cat extends Animal {public String noise() {return "move";}}...Animal animal = new Dog();Cat cat = (Cat) animal;System.out.println(cat.noise());Q: 执行结果A: E) 在运行时会抛出一个错误E: 编译时可以通过,但运行时将出现类型转化错误28.public class Car {private int wheelCount;private String vin;public Car(String vin) {this.vin = vin;this.wheelCount = 4;}public String extend() {return "zoom zoom";}public String getInfo() {return "vin: " + vin + " wheels: " + wheelCount;}}public class MeGo extends Car {public MeGo(String vin) {this.wheelCount = 3;}}Q: 要改哪两个地方来避免编译错误A: D) 在MeGo的构造中加入super(vin);E) 更改Car中的wheelCount属性的修饰符为protected E: 考察构造函数和继承29.interface A {public int getValue();}class B implements A {public int getValue() {return 1;}}class C extends B {// insert code here,Line 15}Q: 哪三段代码可以插入第15行,利用多态性A: B) public void add(B b) {b.getValue();}C) public void add(A a) {a.getValue();}D) public void add(A a,B b) {a.getValue();}E: 因为题目规定要利用多态,那么参数只能是C类的超类30.certkiller = new ReallyBigObject();// more code herecertkiller = null;/* insert code here */ // Line 14Q: 在第14行插入什么代码实现垃圾回收A: A) System.gc();31.class Foo {private int x;public Foo(int x) {this.x = x;}public void setX(int x) {this.x = x;}public int getX() {return x;}}public class Submit {static Foo fooBar(Foo foo) {foo = new Foo(100);return foo;}public static void main(String[] args) {Foo foo = new Foo(300);System.out.print(foo.getX() + ".");Foo fooFoo = fooBar(foo);System.out.print(foo.getX() + ".");System.out.print(fooFoo.getX() + ".");foo = fooBar(fooFoo);System.out.print(foo.getX() + ".");System.out.print(fooFoo.getX());}}Q: 执行结果A: B) 300.300.100.100.100E: 注意对象传递是引用传递,形参32.Q: 创建一个类Book,需要用到类Paper,而类Paper在myLib.jar中。
英文SCJP模拟题200道附答案

英文SCJP模拟题200道附答案,因为目录分隔符不正确。
3)执行此代码时,不会在硬盘上创建文件。
4)如果文件已经存在,运行时将引发异常。
5)代码无法编译,因为这不是文件类的有效构造函数。
问题7:关于随机访问文件类,下列哪项陈述是正确的?1)如果使用\模式创建时指定的文件不存在,则会引发IOException。
2)这个类有一个允许从硬盘上删除文件的方法。
3)可以将这个类与DataInputStream类结合使用。
4)当与\模式一起使用时,如果指定的文件不存在,它将在磁盘驱动器上创建。
5)有读和写主词的方法(例如,readInt(),writeInt(),等等)。
考虑下面这段代码,并从下面选择正确的语句。
1.字符串s =新字符串(\ 2 . s . replace(“d”、“q”);3.系统输出打印输入。
1)代码编译失败,在第2行报告了一个错误。
字符串是不可变的,因此replace()方法毫无意义。
2)代码编译正确,并显示文本\ 3)代码编译正确,并显示文本\4)代码编译,但是在执行第2行时会引发异常。
5)代码编译,但是在第3行抛出异常。
Q9下列哪个关键字可以应用到界面的变量或方法中。
1)静态2)私有3)同步4)受保护5)公共Q10真或假。
只有框架可以包含菜单栏或下拉菜单。
1)真2)假。
Q11考虑以下代码,选择正确的语句:1.甲级2.受保护的int方法(){ 3。
} 4。
} 5。
6.B类扩展了A{ 7。
int方法(){ 8。
} 9。
}1)代码无法编译,因为您不能重写一个比其父方法更私有的方法。
2)代码无法编译,因为方法()被声明为受保护的,因此对任何子类都不可用。
3)代码编译正确,但是在运行时抛出一个空指针异常。
4)代码无法编译。
但是,可以通过在第7行前加上访问限定符\来正确编译5)代码无法编译。
但是,可以通过在第7行前加上访问限定符\ Q12真或假来进行正确编译。
可抛出类是Java语言中所有异常的超类。
Sun认证Java程序员SCJP考试

Sun认证Java程序员SCJP考试Sun认证Java程序员(SCJP)考试Sun Microsystems在行业中被认为是同行中最具创造性的企业之一,它想尝试新的软件方式和定价模式等等。
下面是店铺整理的关于Sun认证Java程序员(SCJP)考试,欢迎对大家参考!Java程序员(SCJP)考试科目简介考试方式:全英文试题,以电脑作答,在授权的Prometric考试中心参加考试考试科目:Sun Certified Programmer for Java 2 Platform 1.2 考试编号:310-025考试题型:59道选择题及简答题及格标准:答对61%(36题)以上时限:120分钟费用:1500元考试科目:Sun Certified Programmer for Java 2 Platform 1.4 考试编号:310-035考试题型:59道选择题及简答题及格标准:答对61%(36题)以上时限:120分钟费用:1500元Java程序员(SCJP)考试科目的区别SCJP的四个科目310-025、310-035、310-055、310-056的区别如下:Sun Certified Programmer for Java 2 Platform 1.2(310-025)表明你掌握了JDK1.2的'知识。
Sun Certified Programmer for Java 2 Platform 1.4(310-035)表明你掌握了JDK1.4的知识。
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0(310-055)表明你掌握了JDK1.5的知识。
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 Upgrade Exam(310-056)是从JDK1.2或JDK1.4升级到JDK1.5的考试。
一些SCJP考试题含答案.

一些SCJP考试题含答案Leading the way in IT testing and certification tools,QUESTION NO: 92 Given:1. String foo = “blue”;2. Boolean[]bar = new Boolean [1];3. if (bar[0] {4. foo = “green”;5. }What is the result?A. Foo has the value of “”B. Foo has the value of null.C. Foo has the value of “blue”D. Foo has the value of “green”E. An exception is thrown.F. The code will not compile.Answer: FQUESTION NO: 93Exhibit:1. public class X {2. public static void main (String[]args {3. String s1 = new String (“true”;4. Boolean b1 = new Boolean (true;5. if (s2.equals(b1 {6. System.out.printIn(“Equal”;7. }8. }9. }What is the result?A. The program runs and prints nothing.B. The program runs and prints “Equal”C. An error at line 5 causes compilation to fail.D. The program runs but aborts with an exception. Answer: AQUESTION NO: 94Given:1. public class Foo {2. public static void main (String []args {3. int i = 1;4. int j = i++;5. if ((i>++j && (i++ ==j {6. i +=j;7. }9. }What is the final value of i?A. 1B. 2C. 3D. 4E. 5Answer: BQUESTION NO: 95Exhibit:1. public class X {2. public static void main (String[]args {3. string s = new string (“Hello”;4. modify(s;5. System.out.printIn(s;6. }7.8. public static void modify (String s {9. s += “world!”;10. }11. }What is the result?E. The program runs and prints “Hello”F. An error causes compilation to fail.G. The program runs and prints “Hello world!”H. The program runs but aborts with an exception. Answer: A QUESTION NO: 96Which two are equivalent? (Choose TwoA. 16>4B. 16/2C. 16*4D. 16>>2E. 16/2^2F. 16>>>2Answer: D, EQUESTION NO: 97Exhibit:1. public class X {2. public static void main (String[]args {3. int [] a = new int [1]4. modify(a;5. System.out.printIn(a[0];7.8. public static void modify (int[] a {9. a[0] ++;10. }11. }What is the result?A. The program runs and prints “0”B. The program runs and prints “1”C. The program runs but aborts with an exception.D. An error “possible undefined variable” at line 4 causes compilation to fail.E. An error “possible undefined variable” at line 9 causes compilation to fail. Answer: BQUESTION NO: 98Given:13. public class Foo {14. public static void main (String [] args {15. StringBuffer a = new StringBuffer (“A”;16. Strin gBuffer b = new StringBuffer (“B”;17. operate (a,b;18. system.out.printIn,a + “,” +b-;19.20. static void operate (StringBuffer x, StringBuffer y {21. y.append {x};22. y = x;23.24. }What is the result?A. The code compiles and prints “A,B”.B. Th e code compiles and prints “A, BA”.C. The code compiles and prints “AB, B”.D. The code compiles and prints “AB, AB”.E. The code compiles and prints “BA, BA”.F. The code does not compile because “+” cannot be overloaded for stringBuffer. Answer: BQUESTION NO: 99Given:1. public class X {2. public static void main (String[] args {3. byte b = 127;4. byte c = 126;5. byte d = b + c;6. }7. }Which statement is true?A. Compilation succeeds and d takes the value 253.B. Line 5 contains an error that prevents compilation.C. Line 5 throws an exception indicating “Out of range”D. Line 3 and 4 contain error that prevent compilation.E. The compilation succeeds and d takes the value of 1.Answer: BQUESTION NO: 100Given:1. public class WhileFoo {2. public static void main (String []args {3. int x= 1, y = 6;4. while (y-- {x--;}5. system.out.printIn(“x=” + x “y =” + y;6. }7. }What is the result?A. The output is x = 6 y = 0B. The output is x = 7 y = 0C. The output is x = 6 y = -1D. The output is x = 7 y = -1E. Compilation will fail.Answer: EQUESTION NO: 101Which statement is true?A. The Error class is a untimeException.B. No exceptions are subclasses of Error.C. Any statement that may throw an Error must be enclosed in a try block.D. Any statement that may throw an Exception must be enclosed in a try block.E. Any statement that may thro a runtimeException must be enclosed in a try block. Answer: DQUESTION NO: 102Exhibit:1. int I=1, j=02.3. switch(i {4. case 2:5. j+=6;6.7. case 4:8. j+=1;9.10. default:11. j +=2;12.13. case 0:14. j +=4;15. }16.What is the value of j at line 16?A. 0B. 1C. 2D. 4E. 6Answer: AEQUESTION NO: 103Given:1. switch (i {2. default:3. System.out.printIn(“Hello”;4.What is the acceptable type for the variable i?A. ByteB. LongC. FloatD. DoubleE. ObjectF. A and BG. C and DAnswer: AQUESTION NO: 104You need to store elements in a collection that guarantees that no duplicates are stored. Which twointerfaces provide that capability? (Choose TwoA. Java.util.MapB. Java.util.SetC. Java.util.ListD. Java.util.StoredSetE. Java.util.StoredMapF. Java.util.CollectionAnswer: B, DQUESTION NO: 105Which statement is true for the class java.util.ArrayList?A. The elements in the collection are ordered.B. The collection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.E. The elements in the collections are guaranteed to be synchronized. Answer: AQUESTION NO: 106Exhibit:1. public class X implements Runnable(2. private int x;3. private int y;4.5. public static void main(String[]args6. X that = new X(;7. (new Thread(that.start(;8. (new Thread(that.start(;9.10.11. public void run( (12. for (;; (13. x++;14. y++;15. System.out.printIn(“x=” + x + “, y = ” + y;16.17.18.What is the result?A. Errors at lines 7 and 8 cause compilation to fail.B. The program prints pairs of values for x and y that might not always be the same on the same line(for example, “x=2, y=1”.C. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”.In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”.D. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”followed by “x=2, y=2”.Answer: DQUESTION NO: 107Given:1. public class SyncTest {2. private int x;3. private int y;4. public synchronized void setX (int i (x=1;5. public synchronized void setY (int i (y=1;6. public synchronized void setXY(int 1(set X(i; setY(i;7. public synchronized Boolean check( (return x !=y;8.Under which conditions will check ( return true when called from a different class?A. Check( can never return true.B. Check( can return true when setXY is called by multiple threads.C. Check( can return true when multiple threads call setX and setY separately.D. Check( can only return true if SyncTest is changed to allow x and y to be set separately. Answer: AQUESTION NO: 108Which is a method of the MouseMotionListener interface?A. Public void mouseDragged(MouseEventB. Public boolean mouseDragged(MouseEventC. Public void mouseDragged(MouseMotionEventD. Public boolean MouseDragged(MouseMotionEventE. Public boolean mouseDragged(MouseMotionEvent Answer: AQUESTION NO: 109Given:1. String foo = “base”;2. foo.substring(0,3;3. foo.concat(“ket”;4. foo += “ball”;5.Type the value of foo at line 8.Answer: BASEBALLQUESTION NO 110Given:1. public class Test {2. public static void leftshift(int i, int j {3. i<<=j;4. }5. public static void main(String args[] {6. int i = 4, j = 2;7. leftshift(i, j;8. System.out.printIn(i;9. }10. }What is the result?A. 2B. 4C. 8D. 16E. The code will not compile. Answer: BQUESTION NO 111Given:1. public class Foo {2. private int val;3. public foo(int v (val = v; }4. public static void main (String [] args {5. Foo a = new Foo (10;6. Foo b = new Foo (10;7. Foo c = a;8. int d = 10;9. double e = 10.0;10. }11. }Which three logical expression evaluate to true? (Choose ThreeA. (a ==cB. (d ==eC. (b ==dD. (a ==bE. (b ==cF. (d ==10.0Answer: A, B, FQUESTION NO 112Exhibit:1. public class X {2. private static int a;3.5. public static void main (String[] args {6. modify (a;7. }8.9. public static void modify (int a {10. a++;11. }12. }What is the result?A. The program runs and prints “0”B. The program runs and prints “1”C. The program runs but aborts with an exception.D. En error “possible undefined variable” at line 5 causes compilation to fail.F. En error “possible undefined variable” at line 10 causes compilation to fail. Answer: AQUESTION NO 113Exhibit:1. public class Test {2. public static void replaceJ(string text {3. text.replace (‘j’, ‘l’;4. }5.6. public static void main(String args[] {7. string text = new String (“java”8. replaceJ(text;9. system.out.printIn(text;10. }11. }What is the result?A. The program prints “lava”B. The program prints “java”C. An error at line 7 causes compilation to fail.D. Compilation succeeds but the program throws an exception. Answer: B QUESTION NO 114Which two are equivalent? (Choose TwoA. 3/2B. 3<2C. 3*4D. 3<<2E. 3*2^2F. 3<<<2Answer: C, DQUESTION NO 115What is the numerical range of a char?A. 0 . . . 32767B. 0 . . . 65535C. ?256 . . . 255D. ?32768 . . . 32767E. Range is platform dependent. Answer: BQUESTION NO 116Given:1. public class Test {2. public static void main (String []args {3. unsigned byte b = 0;4. b--;5.6. }7. }What is the value of b at line 5?A. -1B. 255C. 127D. Compilation will fail.E. Compilation will succeed but the program will throw an exception at line 4. Answer: DQUESTION NO 117Given:1. public class Foo {2. public void main (String [] args {3. system.out.printIn(“Hello World.”;4. }5. }What is the result?A. An exception is thrown.B. The code does no compile.C. “Hello World.” Is print ed to the terminal.D. The program exits without printing anything.Answer: AQUESTION NO 118Given:1. //point X2. public class foo (3. public static void main (String[]args throws Exception {4. java.io.printWriter out = new java.io.PrintWriter (5. new java.io.outputStreamWriter (System.out, true;6. out.printIn(“Hello”;7. }8. }Which statement at PointX on line 1 allows this code to compile and run?A. Import java.io.*;B. Include java.io.*;C. Import java.io.PrintWriter;D. Include java.io.PrintWriter;E. No statement is needed.Answer: EQUESTION NO 119Which will declare a method that is available to all members of the same package and can be referencedwithout an instance of the class?A. Abstract public void methoda(;B. Public abstract double methoda(;C. Static void methoda(double d1{}D. Public native double methoda( {}E. Protected void methoda(double d1 {}Answer: CQUESTION NO 120Which type of event indicates a key pressed on a ponent?A. KeyEventB. KeyDownEventC. KeyPressEventD. KeyTypedEventE. KeyPressedEventAnswer: AQUESTION NO 121Exhibit:1. import java.awt.*;2.3. public class X extends Frame {4. public static void main (String [] args {5. X x = new X(;6. x.pack(;7. x.setVisible(true;8. }9.10. public X( {11. setLayout (new BordrLayout(;12. Panel p = new Panel (;13. add(p, BorderLayout.NORTH;14. Button b = new Button (“North”;15. p.add(b:16. Button b = new Button (“South”;17. add(b1, BorderLayout.SOUTH:18. }19. }Which two statements are true? (Choose TwoA. The buttons labeled “North” and “South” will have the s ame width.B. The buttons labeled “North” and “South” will have the same height.C. The height of the button labeled “North” can very if the Frame is resized.D. The height of the button labele d “South” can very if the Frame is resized.E. The width of the button labeled “North” is constant even if the Frame is resized.F. The width of the button labeled “South” is constant even if the Frame is resized. Answer: B, EQUESTION NO 122How can you create a listener class that receives events when the mouse is moved?A. By extending MouseListener.B. By implementing MouseListener.C. By extending MouseMotionListener.D. By implementing MouseMotionListener.E. Either by extending MouseMotionListener or extending MouseListener.F. Either by implementing MouseMotion Listener or implementing MouseListener.Answer: DQUESTION NO 123Which statement is true?A. A grid bag layout can position components such that they span multiple rows and/or columns.B. The “North” region of a border layout is the proper place to locat e a menuBar component in a Frame.C. Components in a grid bag layout may either resize with their cell, or remain centered in that cell attheir preferred size.D. A border layout can be used to position a component that should maintain a constant size evenwhen the container is resized.Answer: AQUESTION NO 124You want a class to have access to members of another class in the same package. Which is the mostrestrictive access modifier that will accomplish that will accomplish this objective?A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is required.Answer: EQUESTION NO 125Which two statements are true regarding the creation of a default constructor? (Choose TwoA. The default constructor initializes method variables.B. The default constructor invokes the no-parameter constructor of the superclass.C. The default constructor initializes the instance variables declared in the class.D. If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates a default constructor.E. The compiler creates a default constructor only when there are no other constructors for the class.Answer: C, EQUESTION NO 126Given:1. public class OuterClass {2. private double d1 1.0;3. //insert code here4. }You need to insert an inner class declaration at line2. Which two inner class declarations are valid?(Choose TwoA. static class InnerOne {public double methoda( {return d1;}}B. static class InnerOne {static double methoda( {return d1;}}C. private class InnerOne {public double methoda( {return d1;}}D. protected class InnerOne {static double methoda( {return d1;}}E. public abstract class InnerOne {public abstract double methoda(;}Answer: C, EQUESTION NO 127Which two declarations prevent the overriding of a method? (Choose TwoA. Final void methoda( {}B. Void final methoda( {}C. Static void methoda( {}D. Static final void methoda( {}E. Final abstract void methoda( {}Answer: A, DQUESTION NO 128Given:1. public class Test {2. public static void main (String args[] {3. class Foo {4. public int i = 3;5. }6. Object o = (Object new Foo(;7. Foo foo = (Fooo;8. System.out.printIn(foo. i;9. }10. }What is the result?A. Compilation will fail.B. Compilation will succeed and the progr am will print “3”C. Compilation will succeed but the program will throw a ClassCastException at line 6.D. Compilation will succeed but the program will throw a ClassCastException at line 7. Answer: BQUESTION NO 129Which two create an instance of an array? (Choose TwoA. int[] ia = new int [15];B. float fa = new float [20];C. char*+ ca = “Some String”;D. Object oa = new float[20];E. Int ia [][] = (4, 5, 6 (1, 2, 3Answer: A, DQUESTION NO 130Given:1. public class ExceptionTest {2. class TestException extends Exception {}3. public void runTest ( throws TestException {}4. public void test ( /* Point X*/ {5. runTest (;6. }7. }At point X on line 4, which code can be added to make the code compile?A. Throws Exception.B. Catch (Exception e.C. Throws RuntimeException.D. Catch (TestException e.E. No code is necessary.Answer: BQUESTION NO 131Exhibit:1. public class SwitchTest {2. public static void main (String []args {3. System.out.PrintIn(“value =” +switchIt(4;4. }5. public static int switchIt(int x {6. int j = 1;7. switch (x {8. case 1: j++;9. case 2: j++;10. case 3: j++;11. case 4: j++;12. case 5: j++;13. default:j++;14. }15. return j + x;16. }17. }What is the output from line 3?A. Value = 3B. Value = 4C. Value = 5D. Value = 6E. Value = 7F. Value = 8Answer: FQUESTION NO 132Which four types of objects can be thrown using the throw statement? (Choose FourA. ErrorB. EventC. ObjectD. ExceptionE. ThrowableF. RuntimeExceptionAnswer: A, D, E, FQUESTION NO 133Given:1. public class ForBar {2. public static void main(String []args {3. int i = 0, j = 5;4. tp: for (;; {5. i ++;6. for(;;7. if(i > --j break tp;8. }9. system.out.printIn(“i = ” + i + “, j = “+ j;10. }11. }What is the result?A. The program runs and prints “i=1, j=0”B. The program runs and prints “i=1, j=4”C. The program runs and prints “i=3, j=4”D. The program runs and prints “i=3, j=0”E. An error at line 4 causes compilation to fail.F. An error at line 7 causes compilation to fail.Answer: AQUESTION NO 134Which two can directly cause a thread to stop executing? (Choose TwoA. Exiting from a synchronized block.B. Calling the wait method on an object.C. Calling the notify method on an object.D. Calling the notifyAll method on an object.E. Calling the setPriority method on a thread object. Answer: B, EQUESTION NO 135Given:1. public class Foo implements Runnable (2. public void run (Thread t {3. system.out.printIn(“Running.”;4. }5. public static void main (String[] args {6. new thread (new Foo(.start(;7.8.What is the result?A. An exception is thrown.B. The program exists without printing anything.C. An error at line 1 causes compilation to fail.D. An error at line 6 causes the compilation to fail.E. “Running” is printed and the program exits. Answer: C QUESTION NO 136Which constructs a DataOutputStream?A. New dataInputStream(“in.txt”;B. New dataInputStream(new file(“in.txt”;C. New dataInputStream(new writer(“in.txt”;D. New dataInputSt ream(new FileWriter(“in.txt”;E. New dataInputStream(new InputStream(“in.txt”;F. New dataInputStream(new FileInputStream(“in.txt”; Answer: F QUESTION NO 137Which can be used to decode charS for output?A. Java.io.InputStream.B. Java.io.EncodedReader.C. Java.io.InputStreamReader.D. Java.io.InputStreamWriter.E. Java.io.BufferedInputStream.Answer: CQUESTION NO 138Given:1. public class Test {2. public static void main (String [] args {3. string foo = “blue”;4. string bar = foo;5. foo = “green”;6. System.out.printIn(bar;7. }8. }What is the result?A. An exception is thrown.B. The code will not compile.C. The program prints “null”D. The program prints “blue”E. The program prints “green”Answer: DQUESTION NO 139Which code determines the int value foo closest to a double value bar?A. Int foo = (int Math.max(bar;B. Int foo = (int Math.min(bar;C. Int foo = (int Math.abs(bar;D. Int foo = (int Math.ceil(bar;E. Int foo = (int Math.floor(bar;F. Int foo = (int Math.round(bar;Answer: FQUESTION NO 140Which two demonstrate encapsulation of data? (Choose TwoA. Member data have no access modifiers.B. Member data can be modified directly.C. The access modifier for methods is protected.D. The access modifier to member data is private.E. Methods provide for access and modification of data. Answer: D, EQUESTION NO 141Exhibit:1. class A {2. public String toString ( {3. return “4”;4. }5. }6. class B extends A {7. 8. public String toString ( {8. return super.toString( + “3”;9. }10. }11. public class Test {12. public static void main(String[]args {13. System.out.printIn(new B(;14. }15. }What is the result?A. Compilation succeeds and 4 is printed.B. Compilation succeeds and 43 is printed.C. An error on line 9 causes compilation to fail.D. An error on line 14 causes compilation to fail.E. Compilation succeeds but an exception is thrown at line 9. Answer: BQUESTION NO 142Which two statements are true? (Choose TwoA. An anonymous inner class can be declared inside of a methodB. An anonymous inner class constructor can take arguments in some situation.C. An anonymous inner class that is a direct subclass that is a direct subclass of Object can implementmultiple interfaces.D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymousinner class that is an immediate subclass of Super that implements a single interface.E. Event if a class Super does not implement any interfaces, it is still possible to define an anonymousinner class that is an immediate subclass of Super that implements multiple interfaces. Answer: A, BQUESTION NO 143Given:1. public class MethodOver {2. private int x, y;3. private float z;4. public void setVar(int a, int b, float c{5. x = a;6. y = b;7. z = c;8. }9. }Which two overload the setVar method? (Choose Two A. void setVar (int a, int b, float c{x = a;y = b;z = c;}B. public void setVar(int a, float c, int b {setVar(a, b, c;}C. public void setVar(int a, float c, int b {this(a, b, c;}D. public void setVar(int a, float b{x = a;z = b;}E. public void setVar(int ax, int by, float cz {x = ax;y = by;z = cz;}Answer: B, DQUESTION NO 144Which statements about static inner classes are true? (Choose TwoA. A static inner class requires a static initializer.B. A static inner class requires an instance of the enclosing class.C. A static inner class has no reference to an instance of the enclosing class.D. A static inner class has access to the non-static members of the outer class.E. Static members of a static inner class can be referenced using the class name of the static inner class.Answer: C, EQUESTION NO 145Given:1. public class X {2. public object m ( {3. object o = new float (3.14F;4. object [] oa = new object [1];5. oa[0]= o;6. o = null;7. oa[0] = null;9. return o;9. }10. }When is the float object created in line 3, eligible for garbage collection?A. Just after line 5.B. Just after line 6.C. Just after line 7.D. Just after line 8(that is, as the method returns.Answer: CQUESTION NO 146Which two interfaces provide the capability to store objects using a key-value pair? (Choose TwoA. Java.util.Map.B. Java.util.Set.C. Java.util.List.D. Java.util.StoredSet.E. Java.util.StoredMap.F. Java.util.Collection.Answer: A, EQUESTION NO 147Which interface does java.util.Hashable implement?A. Java.util.Map.B. Java.util.List.C. Java.util.Hashable.D. Java.util.Collection. Answer: A。
SCJP题目整合带达内考点分析①

Copyright Tarena Corporation,2009.All rights reserved
14. ++x; 15. } while (x < 5); 16. System.out.print(x + "," + y); What is the result? A. 5,6 B. 5,5 C. 6,5 D. 6,6
Question 9 Given: 35. int x= 10; 36. do { 37. x--; 38. } while(x< 10); How many times will line 37 be executed? A. ten times B. zero times C. one to me times D. more than ten times
A. Line 57 will print the value 2. B. Line 57 will print the value 3. C. Compilation will fail because of an error in line 55. D. Compilation will fail because of an error in line 56.
Question 10 Given: 11. public static void main(String[] args) { 12. for (int i=0;i<= 10;i++){ 13. if( i>6) break; 14. }
Copyright Tarena Corporation,2009.All rights reserved
SCJP认证考试题库2

SCJP认证考试题库2What is the result?A. n ullB. zeroC. s omeD. C ompilation failsE. An exception is thrown at runtimeAnswer: ( D )13行会报错,应在15行使用else if 参考大纲:流程控制QUESTION 63Given the exhibit:What is the result?A. testB. ExceptionC. Compilation failsD. NullPointerExceptionAnswer: ( C )18行出错,应该先catch子异常,再catch Exception;13行把args赋null ,14行会报NullPointerException如果没有第13行运行时14行会报ArrayIndexOutOfBoundsException异常。
参考大纲:异常处理QUESTION 64Given the exhibit:What is the result?A. Compilation failsB. aAaA aAa AAaa AaAC. AAaa AaA aAa aAaAD. AaA AAaa aAaA aAaE. aAa AaA aAaA AAaaF. An exception is thrown at runtimeAnswer: ( C )第10行将对strings这个集合做自然排序(ASCII小到大,一个一个比较)Collections.sort(List list) 对list进行排序,对set 不能排序!List里可以放对象,所以当list里面存放的是对象的时候就不能用Collections.sort(List list)去排序了。
因为JVM不知道用什么规则去排序!!只有把对象类实现Comparable接口,然后改写compareTo()参考大纲:集合QUESTION 65Given the exhibit:What is the result?A. 0B. 1C. 2D. 3E. 4F. Compilation fails.G. An exception is thrown at runtimeAnswer: ( D )Set中存放的元素是无序不重复的。
SUN认证Java2程序员考试(SCJP) 试题解析(2)

SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2)whichofthefollowinglinesofcodewillcompilewithouterror?a.inti=0;if(i){system.out.println( hi );}b.booleanb=true;booleanb2=true;if(b==b2){system.out.println(whichtwodemonstratea"hasa"relationship?(choosetwo)a.publicinterfaceperson{}publicclassemployeeextendsperson{}b.publicinterfaceshape{}publicinterfacerectandleextendsshape{}c.publicinterfacecolorable{}publicclassshapeimplementscolorable{}d.publicclassspecies{}publicclassanimal{privatespeciesspecies;}e.interfacecomponent{}classcontainerimplementscomponent{privatecomponent[]children;}解答:d,e点评:在java中代码重用有两种可能的方式,即组合(hasa 关系)和继承(isa 关系)。
hasa 关系是通过定义类的属性的方式实现的;而isa 关系是通过类继承实现的。
本例中选项a、b、c体现了isa 关系;选项d、e体现了hasa 关系。
例题6:whichtwostatementsaretruefortheclassjava.util.treeset?(ch oosetwo)a.theelementsinthecollectionareordered.b.thecollectionisguaranteedtobeimmutable.c.theelementsinthecollectionareguaranteedtobeunique.d.theelementsinthecollectionareaccessedusingauniquekey.e.theelementsinthecollectionareguaranteedtobesynchroni zed解答:a,c点评:treeset类实现了set接口。
SCJP历年考题

Question No: 1Given:1. public class test (2. public static void main (String args[]) {3. int i = 0xFFFFFFF1;4. int j = ~i;5.6. }7. )What is the decimal value of j at line 5?A. 0B. 1C. 14D. –15E. An error at line 3 causes compilation to fail.F. An error at line 4 causes compilation to fail. Answer: DQuestion No: 2Given:Integer i = new Integer (42);Long 1 = new Long (42);Double d = new Double (42.0);Which two expressions evaluate to True? (Choose Two)A. (i ==1)B. (i == d)C. (d == 1)D. (i.equals (d))E. (d.equals (i))F. (i.equals (42))Answer: D, EQuestion No: 3Exhibit :1. public class test (2. private static int j = 0;3.4. private static boolean methodB(int k) (5. j += k;6. return true;6. )7.8. public static void methodA(int i) {9. boolean b:10. b = i < 10 | methodB (4);11. b = i < 10 || methodB (8); 12. )13.14. public static void main (String args[] } (15. methodA (0);16. system.out.printIn(j);17. )18. )What is the result?A. The program prints “0”B. The program prints “4”C. The program prints “8”D. The program prints “12”E. The code does not complete.Answer: BQuestion No: 4Given1. Public class test (2. Public static void main (String args[]) (3. System.out.printIn (6 ^ 3);4. )5. )What is the output?Answer: 5Question No: 5Given:1. public class Foo {2. public static void main (String [] args) {3. StringBuffer a = new StringBuffer (“A”);4. StringBuffer b = new StringBuffer (“B”);5. operate (a,b);6. system.out.printIn{a + “,”+b};7. )8. static void operate (StringBuffer x, StringBuffer y) {9. x.append {y};10. y = x;11. )12. }What is the result?A. The code compiles and prints “A,B”.B. The code compiles and prints “A,A”.C. The code compiles and prints “B,B”.D. The code compiles and prints “AB,B”.E. The code compiles and prints “AB,AB”.F. The code does not compile because “+”cannot beoverloaded for StringBuffer.Answer: DQuestion No: 6Exhibit:1. Public class test (2. Public static void stringReplace (String text) (3. Text = text.replace (‘j' , ‘i');4. )5.6. public static void bufferReplace (StringBuffer text) (7. text = text.append (“C”)8. )9.10. public static void main (String args[]} (11. String textString = new String (“java”);12. StringBuffer text BufferString = new StringBuffer (“java”);13.14. stringReplace (textString);15. BufferReplace (textBuffer);16.17. System.out.printIn (textString + textBuffer);18. }19. )What is the output?Answer: javajavaCQuestion No: 7Exhibit:1. public class test {2. public static void add3 (Integer i) }3. int val = i.intValue ( );4. val += 3;5. i = new Integer (val);6. }7.8. public static void main (String args [ ] ) {9. Integer i = new Integer (0);10. add3 (i);11. system.out.printIn (i.intValue ( ) );12. }13. )What is the result?A. Compilation will fail.B. The program prints “0”.C. The program prints “3”.D. Compilation will succeed but an exception will be thrown at line 3.Answer: BQuestion No: 8Given:1. public class ConstOver {2. public ConstOver (int x, int y, int z) {3. }4. }Which two overload the ConstOver constructor? (Choose Two)A. ConstOver ( ) { }B. Protected int ConstOver ( ) { }C. Private ConstOver (int z, int y, byte x) { }D. Public Object ConstOver (int x, int y, int z) { }E. Public void ConstOver (byte x, byte y, byte z) { } Answer: A, CQuestion No: 9Given:1. public class MethodOver {2. public void setVar (int a, int b, float c) {3. }4. }Which two overload the setVar method? (Choose Two)A. Private void setVar (int a, float c, int b) { }B. Protected void setVar (int a, int b, float c) { }C. Public int setVar (int a, float c, int b) (return a;)D. Public int setVar (int a, int b, float c) (return a;)E. Protected float setVar (int a, int b, float c) (return c;)Answer: A, CQuestion No: 10Given:1. class BaseClass {2. Private float x = 1.0f ;3. protected float getV ar ( ) ( return x;)4. }5. class Subclass extends BaseClass (6. private float x = 2.0f;7. //insert code here8. )Which two are valid examples of method overriding? (Choose Two)A. Float getVar ( ) { return x;}B. Public float getVar ( ) { return x;}C. Float double getVar ( ) { return x;}D. Public float getVar ( ) { return x;}E. Public float getVar (float f ) { return f;} Answer: B, DQuestion No: 11Which two demonstrate an “is a”relationship? (Choose Two)A. public interface Person { }public class Employee extends Person { }B. public interface Shape { }public class Employee extends Shape { }C. public interface Color { }public class Employee extends Color { }D. public class Species { }public class Animal (private Species species;)E. interface Component { }Class Container implements Component (Private Component[ ] children;)Answer: D, EQuestion No: 12Which statement is true?A. An anonymous inner class may be declared as final.B. An anonymous inner class can be declared as private.C. An anonymous inner class can implement multiple interfaces.D. An anonymous inner class can access final variables in any enclosing scope.E. Construction of an instance of a static inner class requires an instance of the enclosing outer class. Answer: DQuestion No 13Given:1. package foo;2.3. public class Outer (4. public static class Inner (5. )6. )Which statement is true?A. An instance of the Inner class can be constructed with “new Outer.Inner ()”B. An instance of the inner class cannot be constructed outside of package foo.C. An instance of the inner class can only be constructed from within the outer class.D. From within the package bar, an instance of the inner class can be constructed with “new inner()”Answer: AQuestion No 14Exhibit:1. public class enclosingone (2. public class insideone{}3. )4. public class inertest(5. public static void main (string[]args)(6. enclosingone eo= new enclosingone ();7. //insert code here8. )9. )Which statement at line 7 constructs an instance of the inner class?A. InsideOnew ei= eo.new InsideOn();B. Eo.InsideOne ei = eo.new InsideOne();C. InsideOne ei = EnclosingOne.new InsideOne();D. EnclosingOne.InsideOne ei = eo.new InsideOne(); Answer: DQuestion No 15Exhibit:1. interface foo {2. int k = 0;3. ]4.5. public class test implements Foo (6. public static void main(String args[]) (7. int i;8. Test test = new test ();9. i= test.k;10.i= Test.k;11.i= Foo.k;12.)13.)14.What is the result?A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail. Answer: AQuestion No 16Given:1. //point X2. public class foo (3. public static void main (String[]args) throws Exception {4. printWriter out = new PrintWriter (new5. java.io.outputStreamWriter (System.out), true;6. out.printIn(“Hello”);7. }8. )Which statement at PointX on line 1 allows this code to compile and run?A. Import java.io.PrintWriter;B. Include java.io.PrintWriter;C. Import java.io.OutputStreamWriter;D. Include java.io.OutputStreamWriter;E. No statement is needed.Answer: AQuestion No 17Which two statements are reserved words in Java? (Choose Two)A. RunB. ImportC. DefaultD. ImplementAnswer: B, CQuestion No 18Which three are valid declarations of a float? (Choose Three)A. Float foo = -1;B. Float foo = 1.0;C. Float foo = 42e1;D. Float foo = 2.02f;E. Float foo = 3.03d;F. Float foo = 0x0123;Answer: A, D, FQuestion No 19Given:8. int index = 1;9. boolean[] test = new Boolean[3]; 10. boolean foo= test [index];What is the result?A. Foo has the value of 0.B. Foo has the value of null.C. Foo has the value of true.D. Foo has the value of false.E. An exception is thrown.F. The code will not compile. Answer: DQuestion No 20Given:1. public class test(2. public static void main(string[]args){3. string foo = args [1];4. string foo = args [2];5. string foo = args [3];6. }7. }And command line invocation:Java Test red green blueWhat is the result?A. Baz has the value of “”B. Baz has the value of nullC. Baz has the value of “red”D. Baz has the value of “blue”E. Bax has the value of “green”F. The code does not compile.G. The program throws an exception. Answer: GQuestion No 21Given:8. int index = 1;9. int [] foo = new int [3];10.int bar = foo [index];11.int baz = bar + index;What is the result?A. Baz has the value of 0B. Baz has the value of 1C. Baz has the value of 2D. An exception is thrown.E. The code will not compile. Answer: BQuestion No 22Given:1. public class foo {2. public static void main (String[]args) {3. String s;4. system.out.printIn (“s=”+ s);5. }6. }What is the result?A. The code compiles and “s=”is printed.B. The code compiles and “s=null”is printed.C. The code does not compile because string s is not initialized.D. The code does not compile because string s cannot be referenced.E. The code compiles, but a NullPointerException is thrown when toString is called.Answer: CQuestion No 23Which will declare a method that forces a subclass to implement it?A. Public double methoda();B. Static void methoda (double d1) {}C. Public native double methoda();D. Abstract public void methoda();E. Protected void methoda (double d1){} Answer: DQuestion No 24You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective?A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is qualifiedAnswer: CQuestion No 25Given:1. abstract class abstrctIt {2. abstract float getFloat ();3. )4. public class AbstractTest extends AbstractIt {5. private float f1= 1.0f;6. private float getFloat () {return f1;}7. }What is the result? A. Compilation is successful.B. An error on line 6 causes a runtime failure.C. An error at line 6 causes compilation to fail.D. An error at line 2 causes compilation to fail. Answer: CQuestion No 26Exhibit:1. public class test(2. public int aMethod()[3. static int i=0;4. i++;5. return I;6. )7. public static void main (String args[]){8. test test = new test();9. test.aMethod();10.int j = test.aMethod();11.System.out.printIn(j);12.]13.}What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “0”C. Compilation will succeed and the program will print “1”D. Compilation will succeed and the program will print “2”Answer: DQuestion No 27Given:1. class super {2. public float getNum() {return3.0f;}3. )4.5. public class Sub extends Super {6.7. )Which method, placed at line 6, will cause a compiler error?A. Public float getNum() {return 4.0f; }B. Public void getNum () { }C. Public void getNum (double d) { }D. Public double getNum (float d) {retrun 4.0f; } Answer: BQuestion No 28Which declaration prevents creating a subclass of an outer class?A. Static class FooBar{}B. Private class FooBar{}C. Abstract public class FooBar{}D. Final public class FooBar{}E. Final abstract class FooBar{}Answer: DQuestion No 29Given:1. byte [] arry1, array2[];2. byte array3 [][];3. byte[][] array4;If each array has been initialized, which statement will cause a compiler error?A. Array2 = array1;B. Array2 = array3;C. Array2 = array4;D. Both A and BE. Both A and CF. Both B and CAnswer: FQuestion No 30Exhibit:1. class super (2. public int I = 0;3.4. public super (string text) (5. I = 16. )7. )8.9. public class sub extends super (10. public sub (string text) (11. i= 212. )13.14. public static void main (straing args[]) (15. sub sub = new sub (“Hello”);16. system.out. PrintIn(sub.i);17. )18. )What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “0”C. Compilation will succeed and the program will print “1”D. Compilation will succeed and the program will print “2”Answer: AQuestion No 31Given:1. public class returnIt (2. returnType methodA(byte x, double y) (3. return (short) x/y * 2;4. )5. )What is the valid returnType for methodA in line 2?A. IntB. ByteC. LongD. ShortE. FloatF. DoubleAnswer: FQuestion No 32Given the ActionEvent, which method allows you to identify the affected component?A. GetClass.B. GetTarget.C. GetSource.D. GetComponent.E. GetTargetComponent.Answer: CQuestion No 33Which is a method of the MouseMotionListener interface?A. Public void mouseMoved(MouseEvent)B. Public boolean mouseMoved(MouseEvent)C. Public void mouseMoved(MouseMotionEvent)D. Public boolean MouseMoved(MouseMotionEvent)E. Public boolean mouseMoved(MouseMotionEvent) Answer: AQuestion No 34Exhibit:1. import java.awt*;2.3. public class X extends Frame (4. public static void main(string []args) (5. X x = new X ();6. X.pack();7. x.setVisible(true);8. )9.10. public X () (11. setlayout (new GridLayout (2,2));12.13. Panel p1 = new panel();14. Add(p1);15. Button b1= new Button (“One”);16. P1.add(b1);17.18. Panel p2 = new panel();19. Add(p2);20. Button b2= new Button (“Two”);21. P2.add(b2);22.23. Button b3= new Button (“Three”);24. add(b3);25.26. Button b4= new Button (“Four”);27. add(b4);28. )29. )Which two statements are true? (Choose Two)A. All the buttons change height if the frame height is resized.B. All the buttons change width if the Frame width is resized.C. The size of the button labeled “One”is constant even if the Frame is resized.D. Both width and height of the button labeled “Three”might change if the Frame is resized. Answer: C, DQuestion No 35You are assigned the task of building a panel containing a TextArea at the top, a label directly below it,and a button directly below the label. If the three components are added directly to the panel. Which layout manager can the panel use to ensure that the TextArea absorbs all of the free vertical space when the panel is resized?A. GridLayout.B. CardLayout.C. FlowLayout.D. BorderLayout.E. GridBagLayout.Answer: EQuestion No 36Which gets the name of the parent directory file “file.txt”?A. String name= File.getParentName(“file.txt”);B. String name= (new File(“file.txt”)).getParent();C. String name = (newFile(“file.txt”)).getParentName();D. String name= (newFile(“file.txt”)).getParentFile();E. Directory dir=(new File(“file.txt”)).getParentDir();String name= dir.getName();Answer: BQuestion No 37Which can be used to encode charS for output?A. Java.io.OutputStream.B. Java.io.OutputStreamWriter.C. Java.io.EncodeOutputStream.D. Java.io.EncodeWriter.E. Java.io.BufferedOutputStream.Answer: BQuestion No 38The file “file.txt”exists on the file system and contsins ASCII text.Given:38. try {39. File f = new File(“file.txt”);40. OutputStream out = new FileOutputStream(f, true);41. }42. catch (IOException) {}What is the result?A. The code does not compile.B. The code runs and no change is made to the file.C. The code runs and sets the length of the file to 0.D. An exception is thrown because the file is not closed.E. The code runs and deletes the file from the file system.Answer: AQuestion No 39Which constructs a DataOutputStream?A. New dataOutputStream(“out.txt”);B. New dataOutputStream(new file(“out.txt”));C. New dataOutputStream(new writer(“out.txt”));D. New dataOutputStream(newFileWriter(“out.txt”));E. New dataOutputStream(newOutputStream(“out.txt”));F. New dataOutputStream(new FileOutputStream(“out.txt”));Answer: FQuestion No 40What writes the text “”to the end of the file “file.txt”?A. OutputStream out= new FileOutputStream (“file.txt”);Out.writeBytes (“/n”);B. OutputStream os= new FileOutputStream (“file.txt”, true);DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);C. OutputStream os= new FileOutputStream (“file.txt”);DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);D. OutputStream os= new OutputStream (“file.txt”, true);DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);Answer: BQuestion No 41Given:1. public class X (2. public object m () {3. object o = new float (3.14F);4. object [] oa = new object [1];5. oa[0]= o;6. o = null;7. return oa[0];8. }9. }When is the float object created in line 3, eligible for garbage collection? A. Just after line 5B. Just after line 6C. Just after line 7 (that is, as the method returns)D. Never in this method.Answer: DQuestion No 42Given:3. string foo = “ABCDE”;4. foo.substring(3);5. foo.concat(“XYZ”);6.Type the value of foo at line 6.Answer: ABCDEQuestion No 43Which method is an appropriate way to determine the cosine of 42 degrees?A. Double d = Math.cos(42);B. Double d = Math.cosine(42);C. Double d = Math.cos(Math.toRadians(42));D. Double d = Math.cos(Math.toDegrees(42));E. Double d = Math.cosine(Math.toRadians(42)); Answer: CQuestion No 44You need to store elements in a collection that guarantees that no duplicates are stored and all elementscan be accessed in natural order. Which interface provides that capability?A. Java.util.Map.B. Java.util.Set.C. Java.util.List.D. Java.util.StoredSet.E. Java.util.StoredMap.F. Java.util.Collection.Answer: DQuestion No 45Which statement is true for the classjava.util.HashSet?A. The elements in the collection are ordered.B. The collection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.E. The elements in the collections are guaranteed to be synchronized.Answer: CQuestion No 46Given:1. public class IfTest (2. public static void main(string[]args) {3. int x = 3;4. int y = 1;5. if (x = y)6. system.out.printIn(“Not equal”);7. else8. system.out.printIn(“Equal”);9. }10. )What is the result?A. The output is “Equal”B. The output in “Not Equal”C. An error at line 5 causes compilation to fall.D. The program executes but does not print a message.Answer: CQuestion No 47Exhibit:1. public class test (2. public static void main(string args[]) {3. int 1= 0;4. while (i) {5. if (i==4) {6. break;7. )8. ++i;9. )10.11. )12. )What is the value of i at line 10?A. 0B. 3C. 4D. 5E. The code will not compile.Answer: EQuestion No 48Given: 3. int i= 1, j= 10 ;4. do (5. if (i++> --j) continue;6. ) while (i<5);After execution, what are the values for I and j?A. i = 6 and j= 5B. i = 5 and j= 5C. i = 6 and j= 4D. i = 5 and j= 6E. i = 6 and j= 6Answer: DQuestion No 49Given:1. switch (i) {2. default:310-025Leading the way in IT testing and certification tools, - 27 -3. System.out.printIn(“Hello”);4. )What are the two acceptable types for the variable i? (Choose Two)A. CharB. ByteC. FloatD. DoubleE. ObjectAnswer: A, BQuestion No 50Given:1. public class foo {2. public static void main (string[]args)3. try {return;}4. finally {system.out.printIn(“Finally”);}5. }6. )What is the result?A. The program runs and prints nothing.B. The program runs and prints “Finally”C. The code compiles, but an exception is thrown at runtime.D. The code will not compile because the catch block is missing.Answer: BQuestion No 51Exhibit:1. import java.io.IOException;2. public class ExceptionTest(3. public static void main (String[]args)4. try (5. methodA();6. ) catch (IOException e) (7. system.out.printIn(“Caught IOException”);8. ) catch (Exception e) (9. system.out.printIn(“Caught Exception”);10. )11. )12. public void methodA () {13. throw new IOException ();14. )15. )What is the result?A. The code will not compile.B. The output is caught exception.C. The output is caught IOException.D. The program executes normally without printing a message.Answer: AQuestion No 52Exhibit:1. public class test {2. public static string output = “”3.4. public static void foo(int i) {5. try {6. if(i= =1) {7. throw new Exception ();8. }9. output += “1”;10. )11. catch(Exception e) {12. output += “2”;13. return;14. )15. finally (16. output += “3”;17. )18. output += “4”;19. )20. 21. public static void main (string args[]) (22. foo(0);23. foo(1);24.25. )26. )What is the value of the variable output at line 24? Answer: 13423Question No 53Given:1. public class Foo implements Runnable (2. public void run (Thread t) {3. system.out.printIn(“Running.”);4. }5. public static void main (String[] args) {6. new thread (new Foo()).start();7. )8. )What is the result?A. An exception is thrown.B. The program exists without printing anything.C. An error at line 1 causes compilation to fail.D. An error at line 2 causes the compilation to fail.E. “Running”is printed and the program exits. Answer: DQuestion No 54Which statement is true?A. If only one thread is blocked in the wait method of an object, and another thread executes themodify on that same object, then the first thread immediately resumes execution.B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.C. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call.D. If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of thenotify call.Answer: BQuestion No 55Which two CANNOT directly cause a thread to stop executing? (Choose Two)A. Calling the yield method.B. Calling the wait method on an object.C. Calling the notify method on an object.D. Calling the notifyAll method on an object.E. Calling the start method on another Thread object. Answer: C, DQuestion No 56Which two can be used to create a new Thread? (Choose Two)A. Extend ng.Thread and override the run method.B. Extend ng.Runnable and override the start method.C. Implement ng.thread and implement the run method.D. Implement ng.Runnable and implement the run method.E. Implement ng.Thread and implement the start method.Answer: A, DQuestion No 54Which statement is true?A. If only one thread is blocked in the wait method of an object, and another thread executes themodify on that same object, then the first thread immediately resumes execution.B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.C. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call.D. If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes notify call.Answer: BQuestion No 55Which two CANNOT directly cause a thread to stop executing? (Choose Two)A. Calling the yield method.B. Calling the wait method on an object.C. Calling the notify method on an object.D. Calling the notifyAll method on an object.E. Calling the start method on another Thread object. Answer: C, DQuestion No 56Which two can be used to create a new Thread? (Choose Two)A. Extend ng.Thread and override the run method.B. Extend ng.Runnable and override the start method.C. Implement ng.thread and implement the run method.D. Implement ng.Runnable and implement the run method.E. Implement ng.Thread and implement the start method.Answer: A, DQuestion No 57Given:1. public class SyncTest (2. private int x;3. private int y;4. private synchronized void setX (int i) (x=1;)5. private synchronized void setY (int i) (y=1;)6. public void setXY(int 1)(set X(i); setY(i);)7. public synchronized Boolean check() (returnx !=y;)8. )Under which conditions will check () return true when called from a different class?A. Check() can never return true.B. Check() can return true when setXY is called by multiple threads.C. Check() can return true when multiple threads call setX and setY separately.to allow x and y to be set separately.Answer: BQuestion No 58Exhibit:1. class A implements runable (2. int i;3. public void run () (4. try (5. thread.sleep(5000);6. i= 10;7. ) catch(InterruptedException e) {}8. )9. )10.11. public class Test {12. public static void main (string args[]) (13. try (14. A a = new A ();15. Thread t = new Thread (a);16. t.start();17.18. int j= a.i;19.20. ) catch (Exception e) {}21. )22. )Which statement al line 17 will ensure that j=10 at line 19?A. a.wait();B. t.wait();C. t.join();D. t.yield();E. t.notify();F. a.notify();G. t.interrupt();Answer: CQuestion No 59Exhibit:1. public class X implements Runnable (2. private int x;3. private int y;4.5. public static void main(String [] args) (6. X that = new X();7. (new Thread(that)) . start( ); 8. (new Thread(that)) . start( );9. )10.11. public synchronized void run( ) (12. for (;;) (13. x++;14. y++;15. System.out.printIn(“x = “+ x + “, y = “+ y);16. )17. )18. )What is the result?A. An error at line 11 causes compilation to fail.B. Errors at lines 7 and 8 cause compilation to fail.C. The program prints pairs of values for x and y that might not always be the same on the same line(for example, “x=2, y=1”)D. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1”followed by“x=1, y=1”)E. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1”followed by“x=2s, y=2”)Answer: EQUESTION NO: 60Which two CANNOT directly cause a thread to stop executing? (Choose Two)A. Existing from a synchronized block.B. Calling the wait method on an object.C. Calling notify method on an object.D. Calling read method on an InputStream object.E. Calling the SetPriority method on a Thread object. Answer: A, CQUESTION NO: 61Exhibit1. public class SyncTest{2. public static void main(String[] args) {3. final StringBuffer s1= new StringBuffer();4. final StringBuffer s2= new StringBuffer();5. new Thread () {6. public void run() {。
scjp考试

前言本书的主要目的,是帮助读者准备并通过Sun Microsystem公司Java 6或Java 5的SCJP认证考试。
就考试范围而言,Java 6和Java 5几乎相同,它们都比以前的Java 1.4考试更广。
对于本书的余下部分,我们完全参考Java 6的考试,但是要记住,除了增加了System.Console类和Navigable集合之外,Java 5和Java 6考试在范围上是相同的。
我们建议读者参加Java 6考试而非Java 5考试,但是如果你真的决定选择后者,则本书同样适合你。
新的考试的目标触及了许多更常使用的Java API。
这里的关键字是“触及”。
命题者的想法是:通过了考试,就表明考生理解了基本的API,比如用于文件I/O以及正则表达式的那些API。
本书完全遵循实际考试的范围和深度。
例如,在读完这本书之后,你可能不会成为正则表达式行家,但如果你仔细研究了相关内容,并且自测题也做得不错,则就已经对正则表达式有了基本的理解,同样在真正的考试中也会表现不赖。
在学习完整本书之后,你应当充满信心,相信自己已经全面复习过了Sun为考试而设立的全部考试目标。
.本书内容本书是按照最优化SCJP Java 6认证考试所覆盖的主题的学习而组织的。
只要有可能,就会将本书各个章节的组织与Sun的认证目标平行,但有时会将几个目标混合在一起,也有部分目标是重复的,以便将学习材料所体现的主题组织得更好。
除了完全覆盖SCJP Java 6认证考试之外,本书还在配套光盘上包含了另外的8章,它们涉及Sun SCJD认证考试的重要方面。
各章内容本书各章的结构旨在唤起读者对重要内容的注意,强化重点,并针对考试提供有用的帮助。
让我们看一下在各章中都可以找到的结构。
每章都以认证目标开始——为了通过与这一章的主题相关的考试部分,读者需要知道的内容。
●认证目标。
认证目标的标题表明了这一章的目标,因此当看到它时,总是能知道目标是什么。
SCJP官方题库

QUESTION NO: 1Given:1. public class Threads2 implements Runnable {2.3. public void run() {4. System.out.println("run.");5. throw new RuntimeException("Problem");6. }7. public static void main(String[] args) {8. Thread t = new Thread(new Threads2());9. t.start();10. System.out.println("End of method.");11. }12. }Which two can be results? (Choose two.)A. ng.RuntimeException: ProblemB. runng.RuntimeException: ProblemC. End of method.ng.RuntimeException: ProblemD. End of method.run.ng.RuntimeException: ProblemE. runng.RuntimeException: ProblemEnd of method.Answer: D,EQUESTION NO: 2Which two statements are true? (Choose two.)A. It is possible for more than two threads to deadlock at once.B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.C. Deadlocked threads release once their sleep() method's sleep duration has expired.D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are usedincorrectly.E. It is possible for a single-threaded application to deadlock if synchronized blocks are usedincorrectly.F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlockingby inserting invocations of Thread.yield().Answer: A,FQUESTION NO: 3Given:7. void waitForSignal() {8. Object obj = new Object();9. synchronized (Thread.currentThread()) {10. obj.wait();11. obj.notify();12. }13. }Which statement is true?A. This code can throw an InterruptedException.B. This code can throw an IllegalMonitorStateException.C. This code can throw a TimeoutException after ten minutes.D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.E. A call to notify() or notifyAll() from another thread might cause this method to completenormally.F. This code does NOT compile unless "obj.wait()" is replaced with "((Thread)obj).wait()".Answer: BQUESTION NO: 4Click the Exhibit button.What is the output if the main() method is run?A. 4B. 5C. 8D. 9E. Compilation fails.F. An exception is thrown at runtime.G. It is impossible to determine for certain. Answer: DQUESTION NO: 5Given:11. class PingPong2 {12. synchronized void hit(long n) {13. for(int i = 1; i < 3; i++)14. System.out.print(n + "-" + i + " ");15. }16. }17. public class Tester implements Runnable {18. static PingPong2 pp2 = new PingPong2();19. public static void main(String[] args) {20. new Thread(new Tester()).start();21. new Thread(new Tester()).start();22. }23. public void run() { pp2.hit(Thread.currentThread().getId()); }24. }Which statement is true?A. The output could be 5-1 6-1 6-2 5-2B. The output could be 6-1 6-2 5-1 5-2C. The output could be 6-1 5-2 6-2 5-1D. The output could be 6-1 6-2 5-1 7-1 Answer: BQUESTION NO: 6Given:1. public class Threads4 {2. public static void main (String[] args) {3. new Threads4().go();4. }5. public void go() {6. Runnable r = new Runnable() {7. public void run() {8. System.out.print("foo");9. }10. };11. Thread t = new Thread(r);12. t.start();13. t.start();14. }15. }What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The code executes normally and prints "foo".D. The code executes normally, but nothing is printed. Answer: BQUESTION NO: 7Given:11. public abstract class Shape {12. private int x;13. private int y;14. public abstract void draw();15. public void setAnchor(int x, int y) {16. this.x = x;17. this.y = y;18. }19. }Which two classes use the Shape class correctly? (Choose two.)A. public class Circle implements Shape {private int radius;}B. public abstract class Circle extends Shape { private int radius;}C. public class Circle extends Shape {private int radius;public void draw();}D. public abstract class Circle implements Shape { private int radius;public void draw();}E. public class Circle extends Shape {private int radius;public void draw() {/* code here */}F. public abstract class Circle implements Shape { private int radius;public void draw() { /* code here */ } Answer: B,EQUESTION NO: 8Given:11. public class Barn {12. public static void main(String[] args) {13. new Barn().go("hi", 1);14. new Barn().go("hi", "world", 2);15. }16. public void go(String... y, int x) {17. System.out.print(y[y.length - 1] + " ");18. }19. }What is the result?A. hi hiB. hi worldC. world worldD. Compilation fails.E. An exception is thrown at runtime.Answer: DQUESTION NO: 9Given:10. class Nav{11. public enum Direction { NORTH, SOUTH, EAST, WEST }12. }13. public class Sprite{14. // insert code here15. }Which code, inserted at line 14, allows the Sprite class to compile?A. Direction d = NORTH;B. Nav.Direction d = NORTH;C. Direction d = Direction.NORTH;D. Nav.Direction d = Nav.Direction.NORTH; Answer: DQUESTION NO: 10Click the Exhibit button.Which statement is true about the classes and interfaces in the exhibit?A. Compilation will succeed for all classes and interfaces.B. Compilation of class C will fail because of an error in line 2.C. Compilation of class C will fail because of an error in line 6.D. Compilation of class AImpl will fail because of an error in line 2.Answer: CQUESTION NO: 11Click the Exhibit button.What is the result?A. 4321B. 0000C. An exception is thrown at runtime.D. Compilation fails because of an error in.Answer: DQUESTION NO: 12Given:11. public class Rainbow {12. public enum MyColor {13. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);14. private final int rgb;15. MyColor(int rgb) { this.rgb = rgb; }16. public int getRGB() { return rgb; }17. }; 18. public static void main(String[] args) {19. // insert code here20. }21. }Which code fragment, inserted at line 19, allows the Rainbow class to compile?A. MyColor skyColor = BLUE;B. MyColor treeColor = MyColor.GREEN;C. if(RED.getRGB() < BLUE.getRGB()) { }D. Compilation fails due to other error(s) in the code.E. MyColor purple = new MyColor(0xff00ff);F. MyColor purple = MyColor.BLUE + MyColor.RED; Answer: BQUESTION NO: 13Given:11. class Mud {12. // insert code here13. System.out.println("hi");14. }15. }And the following five fragments:public static void main(String...a) {public static void main(String.* a) {public static void main(String... a) {public static void main(String[]... a) {public static void main(String...[] a) {How many of the code fragments, inserted independently at line 12, compile?A. 0B. 1C. 2D. 3E. 4F. 5Answer: DQUESTION NO: 14Given:5. class Atom {6. Atom() { System.out.print("atom "); }7. }8. class Rock extends Atom {9. Rock(String type) { System.out.print(type); }10. }11. public class Mountain extends Rock {12. Mountain() {13. super("granite ");14. new Rock("granite ");15. }16. public static void main(String[] a) { new Mountain(); }17. }What is the result?A. Compilation fails.B. atom graniteC. granite graniteD. atom granite graniteE. An exception is thrown at runtime.F. atom granite atom graniteAnswer: FQUESTION NO: 15Given:1. interface TestA { String toString(); }2. public class Test {3. public static void main(String[] args) {4. System.out.println(new TestA() {5. public String toString() { return "test"; }6. });7. }8. }What is the result?A. testB. nullC. An exception is thrown at runtime.D. Compilation fails because of an error in line 1.E. Compilation fails because of an error in line 4.F. Compilation fails because of an error in line 5. Answer: AQUESTION NO: 16Given:11. public static void parse(String str) {12. try {13. float f = Float.parseFloat(str);14. } catch (NumberFormatException nfe) {15. f = 0;16. } finally {17. System.out.println(f);18. }19. }20. public static void main(String[] args) {21. parse("invalid");22. }What is the result?A. 0.0B. Compilation fails.C. A ParseException is thrown by the parse method at runtime.D. A NumberFormatException is thrown by the parse method at runtime.Answer: BQUESTION NO: 17Given:1. public class Blip {2. protected int blipvert(int x) { return 0; }3. }4. class Vert extends Blip {5. // insert code here6. }Which five methods, inserted independently at line 5, will compile? (Choose five.)A. public int blipvert(int x) { return 0; }B. private int blipvert(int x) { return 0; }C. private int blipvert(long x) { return 0; }D. protected long blipvert(int x) { return 0; }E. protected int blipvert(long x) { return 0; }F. protected long blipvert(long x) { return 0; }G. protected long blipvert(int x, int y) { return 0; } Answer: A,C,E,F,GQUESTION NO: 18Given:1. class Super {2. private int a;3. protected Super(int a) { this.a = a; }4. }...11. class Sub extends Super {12. public Sub(int a) { super(a); }13. public Sub() { this.a = 5; }14. }Which two, independently, will allow Sub to compile? (Choose two.)A. Change line 2 to:public int a;B. Change line 2 to:protected int a;C. Change line 13 to:public Sub() { this(5); }D. Change line 13 to:public Sub() { super(5); }E. Change line 13 to:public Sub() { super(a); }Answer: C,DQUESTION NO: 19Which Man class properly represents the relationship "Man has a best friend who is a Dog"?A. class Man extends Dog { }B. class Man implements Dog { }C. class Man { private BestFriend dog; }D. class Man { private Dog bestFriend; }E. class Man { private Dog<bestFriend>; }F. class Man { private BestFriend<dog>; } Answer: DQUESTION NO: 20Given:1. package test;2.3. class Target {4. public String name = "hello";5. }What can directly access and change the value of the variable name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: CQUESTION NO: 21Given:11. abstract class Vehicle { public int speed() { return 0; }12. class Car extends Vehicle { public int speed() { return 60; }13. class RaceCar extends Car { public int speed() { return 150; }...21. RaceCar racer = new RaceCar();22. Car car = new RaceCar();23. Vehicle vehicle = new RaceCar();24. System.out.println(racer.speed() + ", " + car.speed()25. + ", " + vehicle.speed());What is the result?A. 0, 0, 0B. 150, 60, 0C. Compilation fails.D. 150, 150, 150E. An exception is thrown at runtime.Answer: DQUESTION NO: 22Given:5. class Building { }6. public class Barn extends Building {7. public static void main(String[] args) {8. Building build1 = new Building();9. Barn barn1 = new Barn();10. Barn barn2 = (Barn) build1;11. Object obj1 = (Object) build1;12. String str1 = (String) build1;13. Building build2 = (Building) barn1;14. }15. }Which is true?A. If line 10 is removed, the compilation succeeds.B. If line 11 is removed, the compilation succeeds.C. If line 12 is removed, the compilation succeeds.D. If line 13 is removed, the compilation succeeds.E. More than one line must be removed for compilation to succeed.Answer: CQUESTION NO: 23A team of programmers is reviewing a proposed API for a new utility class. After some discussion,they realize that they can reduce the number of methods in the API without losing anyfunctionality. If they implement the new design, which two OO principles will they be promoting?A. Looser couplingB. Tighter couplingC. Lower cohesionD. Higher cohesionE. Weaker encapsulationF. Stronger encapsulationAnswer: AQUESTION NO: 24 Given:21. class Money {22. private String country = "Canada";23. public String getC() { return country; }24. }25. class Yen extends Money {26. public String getC() { return super.country; }27. }28. public class Euro extends Money {29. public String getC(int x) { return super.getC(); }30. public static void main(String[] args) {31. System.out.print(new Yen().getC() + " " + newEuro().getC());32. }33. }What is the result?A. CanadaB. nullCanadaC. Canada nullD. Canada CanadaE. Compilation fails due to an error on line 26.F. Compilation fails due to an error on line 29. Answer: EQUESTION NO: 25Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:13. import java.io.*;14. class Food implements Serializable {int good = 3;}15. class Fruit extends Food {int juice = 5;}16. public class Banana extends Fruit {17. int yellow = 4;18. public static void main(String [] args) {19. Banana b = new Banana(); Banana b2 = new Banana();20. b.serializeBanana(b); // assume correct serialization21. b2 = b.deserializeBanana(); // assume correct22. System.out.println("restore "+b2.yellow+b2.juice+b2.good);24. }25. // more Banana methods go here50. }What is the result?A. restore 400B. restore 403C. restore 453D. Compilation fails.E. An exception is thrown at runtime.Answer: CQUESTION NO: 26Given a valid DateFormat object named df, and16. Date d = new Date(0L);17. String ds = "December 15, 2004";18. // insert code hereWhat updates d's value with the date represented by ds?A. 18. d = df.parse(ds);B. 18. d = df.getDate(ds);C. 18. try {19. d = df.parse(ds);20. } catch(ParseException e) { };D. 18. try {19. d = df.getDate(ds);20. } catch(ParseException e) { };Answer: CQUESTION NO: 27Given:11. double input = 314159.26;12. NumberFormat nf =NumberFormat.getInstance(Locale.ITALIAN);13. String b;14. //insert code hereWhich code, inserted at line 14, sets the value of b to 314.159,26?A. b = nf.parse( input );B. b = nf.format( input );C. b = nf.equals( input );D. b = nf.parseObject( input );Answer: BQUESTION NO: 28Given:1. public class TestString1 {2. public static void main(String[] args) {3. String str = "420";4. str += 42;5. System.out.print(str);6. }7. }What is the output?A. 42B. 420C. 462D. 42042E. Compilation fails.F. An exception is thrown at runtime.Answer: DQUESTION NO: 29Which capability exists only in java.io.FileWriter?A. Closing an open stream.B. Flushing an open stream.C. Writing to an open stream.D. Writing a line separator to an open stream. Answer: DQUESTION NO: 30Given that the current directory is empty, and that the user has read and write permissions, andthe following:11. import java.io.*;12. public class DOS {13. public static void main(String[] args) {14. File dir = new File("dir");15. dir.mkdir(); 16. File f1 = new File(dir, "f1.txt");17. try {18. f1.createNewFile();19. } catch (IOException e) { ; }20. File newDir = new File("newDir");21. dir.renameTo(newDir);22. }23. }Which statement is true?A. Compilation fails.B. The file system has a new empty directory named dir.C. The file system has a new empty directory named newDir.D. The file system has a directory named dir, containing a file f1.txt.E. The file system has a directory named newDir, containing a file f1.txt.Answer: EQUESTION NO: 31Given:22. StringBuilder sb1 = new StringBuilder("123");23. String s1 = "123";24. // insert code here25. System.out.println(sb1 + " " + s1);Which code fragment, inserted at line 24, outputs "123abc 123abc"?A. sb1.append("abc"); s1.append("abc");B. sb1.append("abc"); s1.concat("abc");C. sb1.concat("abc"); s1.append("abc");D. sb1.concat("abc"); s1.concat("abc");E. sb1.append("abc"); s1 = s1.concat("abc");F. sb1.concat("abc"); s1 = s1.concat("abc");G. sb1.append("abc"); s1 = s1 + s1.concat("abc");H. sb1.concat("abc"); s1 = s1 + s1.concat("abc"); Answer: EQUESTION NO: 32Click the Exhibit button.Which code, inserted at line 14, will allow this class tocorrectly serialize and deserialize?A. s.defaultReadObject();B. this = s.defaultReadObject();C. y = s.readInt(); x = s.readInt();D. x = s.readInt(); y = s.readInt();Answer: DQUESTION NO: 33Given:1. public class LineUp {2. public static void main(String[] args) {3. double d = 12.345;4. // insert code here5. }6. }Which code fragment, inserted at line 4, produces the output | 12.345|?A. System.out.printf("|%7d| \n", d);B. System.out.printf("|%7f| \n", d);C. System.out.printf("|%3.7d| \n", d);D. System.out.printf("|%3.7f| \n", d);E. System.out.printf("|%7.3d| \n", d);F. System.out.printf("|%7.3f| \n", d);Answer: FQUESTION NO: 34Given:11. public class Test {12. public static void main(String [] args) {13. int x = 5;14. boolean b1 = true;15. boolean b2 = false;16.17. if ((x == 4) && !b2 )18. System.out.print("1 ");19. System.out.print("2 ");20. if ((b2 = true) && b1 )21. System.out.print("3 ");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exception is thrown at runtime. Answer: DQUESTION NO: 35Given:10. interface Foo {}11. class Alpha implements Foo {}12. class Beta extends Alpha {}13. class Delta extends Beta {14. public static void main( String[] args ) {15. Beta x = new Beta(); 16. // insert code here17. }18. }Which code, inserted at line 16, will cause ang.ClassCastException?A. Alpha a = x;B. Foo f = (Delta)x;C. Foo f = (Alpha)x;D. Beta b = (Beta)(Alpha)x;Answer: BQUESTION NO: 36Given:22. public void go() {23. String o = "";24. z:25. for(int x = 0; x < 3; x++) {26. for(int y = 0; y < 2; y++) {27. if(x==1) break;28. if(x==2 && y==1) break z;29. o = o + x + y;30. }31. }32. System.out.println(o);33. }What is the result when the go() method is invoked?A. 00B. 0001C. 000120D. 00012021E. Compilation fails.F. An exception is thrown at runtime.Answer: CQUESTION NO: 37Given:11. static void test() throws RuntimeException {12. try {13. System.out.print("test ");14. throw new RuntimeException();15. }16. catch (Exception ex) { System.out.print("exception "); }17. }18. public static void main(String[] args) {19. try { test(); }20. catch (RuntimeException ex){ System.out.print("runtime "); }21. System.out.print("end ");22. }What is the result?A. test endB. Compilation fails.C. test runtime endD. test exception endE. A Throwable is thrown by main at runtime. Answer: DQUESTION NO: 38Given:33. try {34. // some code here35. } catch (NullPointerException e1) {36. System.out.print("a");37. } catch (Exception e2) {38. System.out.print("b");39. } finally {40. System.out.print("c");41. }If some sort of exception is thrown at line 34, which output is possible?A. aB. bC. cD. acE. abcAnswer: DQUESTION NO: 39Given:31. // some code here32. try {33. // some code here34. } catch (SomeException se) {35. // some code here36. } finally {37. // some code here38. }Under which three circumstances will the code on line 37 be executed? (Choose three.)A. The instance gets garbage collected.B. The code on line 33 throws an exception.C. The code on line 35 throws an exception.D. The code on line 31 throws an exception.E. The code on line 33 executes successfully. Answer: B,C,EQUESTION NO: 40Given:10. int x = 0;11. int y = 10;12. do {13. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: BQUESTION NO: 41Given:1. public class Donkey2 {2. public static void main(String[] args) {3. boolean assertsOn = true;4. assert (assertsOn) : assertsOn = true;5. if(assertsOn) {6. System.out.println("assert is on");7. }8. }9. }If class Donkey is invoked twice, the first time without assertions enabled, and the second timewith assertions enabled, what are the results?A. no outputB. no output assert is onC. assert is onD. no outputAn AssertionError is thrown.E. assert is onAn AssertionError is thrown.Answer: CQUESTION NO: 42Click the Exhibit button.Given:31. public void method() {32. A a = new A();33. a.method1();34. }Which statement is true if a TestException is thrown on line 3 of class B?A. Line 33 must be called within a try block.B. The exception thrown by method1 in class A is not required to be caught.C. The method declared on line 31 must be declared to throw a RuntimeException.D. On line 5 of class A, the call to method2 of class B does not need to be placed in atry/catch block.Answer: BQUESTION NO: 43Given:11. Float pi = new Float(3.14f);12. if (pi > 3) {13. System.out.print("pi is bigger than 3. ");14. }15. else {16. System.out.print("pi is not bigger than 3. ");17. }18. finally {19. System.out.println("Have a nice day.");20. }What is the result?A. Compilation fails.B. pi is bigger than 3.C. An exception occurs at runtime.D. pi is bigger than 3. Have a nice day.E. pi is not bigger than 3. Have a nice day. Answer: AQUESTION NO: 44Given:1. public class Boxer1{2. Integer i;3. int x;4. public Boxer1(int y) {5. x = i+y;6. System.out.println(x);7. }8. public static void main(String[] args) {9. new Boxer1(new Integer(4));10. }11. }What is the result?A. The value "4" is printed at the command line.B. Compilation fails because of an error in line 5.C. Compilation fails because of an error in line 9.D. A NullPointerException occurs at runtime.E. A NumberFormatException occurs at runtime.F. An IllegalStateException occurs at runtime. Answer: DQUESTION NO: 45Given:1. public class Person {2. private String name;3. public Person(String name) { = name; }4. public boolean equals(Person p) {5. return .equals();6. }7. }Which statement is true?A. The equals method does NOT properly override the Object.equals method.B. Compilation fails because the private attribute cannot be accessed in line 5.C. To work correctly with hash-based data structures, this class must also implement thehashCode method.D. When adding Person objects to a java.util.Set collection, the equals method in line 4 willprevent duplicates. Answer: AQUESTION NO: 46Which two statements are true about the hashCode method? (Choose two.)A. The hashCode method for a given class can be used to test for object equality and objectinequality for that class.B. The hashCode method is used by thejava.util.SortedSet collection class to order the elements within that set.C. The hashCode method for a given class can be used to test for object inequality, butNOT object equality, for that class.D. The only important characteristic of the values returned by a hashCode method is that thedistribution of values must follow a Gaussian distribution.E. The hashCode method is used by the java.util.HashSet collection class to group the elementswithin that set into hash buckets for swift retrieval.Answer: C,EQUESTION NO: 47Given:1. public class Score implements Comparable<Score> {2. private int wins, losses;3. public Score(int w, int l) { wins = w; losses = l; }4. public int getWins() { return wins; }5. public int getLosses() { return losses; }6. public String toString() {7. return "<" + wins + "," + losses + ">";8. }9. // insert code here10. }Which method will complete this class?A. public int compareTo(Object o){/*more code here*/}B. public int compareTo(Score other){/*more code here*/}C. public int compare(Score s1,Score s2){/*more code here*/}D. public int compare(Object o1,Object o2){/*more code here*/}Answer: BQUESTION NO: 48Given a pre-generics implementation of a method:11. public static int sum(List list) {12. int sum = 0;13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {14. int i = ((Integer)iter.next()).intValue();15. sum += i;16. }17. return sum;18. }What three changes allow the class to be used with generics and avoid an unchecked warning?(Choose three.)A. Remove line 14.B. Replace line 14 with "int i = iter.next();".C. Replace line 13 with "for (int i : intList) {".D. Replace line 13 with "for (Iterator iter : intList) {".E. Replace the method declaration with "sum(List<int> intList)".F. Replace the method declaration with"sum(List<Integer> intList)".Answer: A,C,FQUESTION NO: 49Given:23. Object [] myObjects = {24. new Integer(12),25. new String("foo"),26. new Integer(5),27. new Boolean(true)28. };29. Arrays.sort(myObjects);30. for(int i=0; i<myObjects.length; i++) {31. System.out.print(myObjects[i].toString());32. System.out.print(" ");33. }What is the result?A. Compilation fails due to an error in line 23.B. Compilation fails due to an error in line 29.C. A ClassCastException occurs in line 29.D. A ClassCastException occurs in line 31.E. The value of all four objects prints in natural order. Answer: CQUESTION NO: 50Given a class Repetition:1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print"pizzapizza"?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition.*;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: FQUESTION NO: 51A UNIX user named Bob wants to replace his chess program with a new one, but he is not surewhere the old one is installed. Bob is currently able to run a Java chess program starting from hishome directory /home/bob using the command:java -classpath /test:/home/bob/downloads/*.jar games.ChessBob's CLASSPATH is set (at login time) to:/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar What is a possible location for the Chess.class file?A. /test/Chess.classB. /home/bob/Chess.classC. /test/games/Chess.classD. /usr/lib/games/Chess.classE. /home/bob/games/Chess.classF. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)Answer: CQUESTION NO: 52Given the following directory structure:bigProject|--source| |--Utils.java||--classes|--And the following command line invocation:javac -d classes source/Utils.javaAssume the current directory is bigProject, what is the result?A. If the compile is successful, Utils.class is added to the source directory.B. The compiler returns an invalid flag error.C. If the compile is successful, Utils.class is added to the classes directory.D. If the compile is successful, Utils.class is added to the bigProject directory.Answer: CQUESTION NO: 53Given:1. package pany.application;2.3. public class MainClass {4. public static void main(String[] args) {}5. }And MainClass exists in the/apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory).Which two java commandsentered at the command line will run MainClass? (Choose two.)A. java MainClass if run from the /apps directoryB. java pany.application.MainClass if run from the /apps directoryC. java -classpath /appspany.application.MainClass if run from any directoryD. java -classpath . MainClass if run from the/apps/com/company/application directory。
SCJP试题集及解析

SCJP试题集及解析1. Which of the following range of short is correct?A. -27 -- 27-1B. 0 – 216-1C. 215 – 215-1D. 231 – 231-1翻译:下面哪些是short型的取值范围。
答案::C解析:短整型的数据类型的长度是16 bits,有符号。
另外需要说明的是java中所有的整(Integral)数(包括byte,short,int,long)全是有符号的。
2. Which declarations of identifiers are legal?A. $personsB. TwoUsersC. *pointD. thisE. _endline翻译:下面哪些是合法的标识符。
答案:A,B,E解析:Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。
3. Which statement of assigning a long type variable to a hexadecimal value is correct?A. long number = 345L;B. long number = 0345;C. long number = 0345L;D. long number = 0x345L翻译:哪些是将一个十六进制值赋值给一个long型变量。
答案D解析:十六进制数以0x开头,long型数以L(大小写均可,一般使用大写,因为小写的l和数字1不易区分)。
4. Which of the following fragments might cause errors?A. String s = "Gone with the wind";String t = " good ";String k = s + t;B. String s = "Gone with the wind";String t;t = s[3] + "one";C. String s = "Gone with the wind";String standard = s.toUpperCase();D. String s = "home directory";String t = s - "directory";翻译:下面的哪些程序片断可能导致错误。
SUN公司SCJP题库讲解学习

S U N公司S C J P题库yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime. Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是boolean Question 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回false Question 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime.Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime. Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; } Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static 代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ )System.out.println(x[i]);Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3) Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成public Question 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils. Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value ofthe variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 tosuggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。
SUN认证SCJP介绍

考试准备
• 题目并不难,但陷阱很多。答题时一定要 细心、冷静。 • 对Java基础的掌少90%的考 题出自题库。 • 死记答案是下策,应该要理解题目考的是 什么知识点、以及答案为什么是那样。 • 题库存在错误。有疑问请汇总、交流。
注意事项 – 乘车路线
• B1 – 八字桥 – B2/B2区间 – 浙江工商大学
注意事项 – 考试过程
• • • • • • • • • • 公共厕所在一楼,仅此一间 前台接待的阿姨很热情,但是需要你自己倒水 过来一个MM(也很亲切)让你登记(Testing ID、身份证号等) 运气好的话马上就可考试,也有可能得等待一会儿(最多只能安排六 人同时考试) 不能携带任何物品进入考场(有柜子存放物品),会提供“草稿纸” (一张A4大小的塑料卡片,绿色、有方格)、笔 MM会帮你启动软件,填写“Test Site Code”等信息……一路操作到 第一道题目出现(貌似连名字都是她给我填的,真的很周到哦,嘿嘿 ~不过这MM好像不太熟悉考试内容,把我第一题给直接跳过了) 全过程有语音及视频监控(MM会提醒你的,这是她的职责),考试 中务必保持安静,有问题随时举手 答完最后一题时可以选择交卷,也可返回检查 答完题后MM可能会请你填一份在线调查问卷 等待几分钟后就可以拿到考试成绩报告了
证书的意义
• • • • 用相同的时间,收获更多的技术。 提升英语水平,为进入外企铺路。 增加面试勇气,顺利通过技术考核。 一段考试经历,圆一个就业梦想。
你值得拥有!
注意事项 – 题目类型
• 选择
– 复选框(注意选择几项的提示) – 单选框 – Exhibit
• 拖拽
– Task
考试、证书寄达流程
• • • •
• • • •
SUN认证Java2程序员考试(SCJP)试题解析

SUN认证Java2程序员考试(SCJP)试题解析
佚名
【期刊名称】《软件》
【年(卷),期】2003(000)012
【摘要】前言无论你是个新手.还是程序设计方面的专家.你都会惊异于Sun公司、Java的无穷魅力。
Java带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once,run anywhere“等软件开发方面的优势。
更重要的一点是。
它提供了一种新颖的表达思想的方式。
一种全新的思维模式。
随着待解决问题的规模不断膨胀.Java彻底的面向对象思想的灵活性就会凸现出来。
毋庸置疑、Java是你开发大型软件时最得心应手的利器或是你转行IT的入门首选。
【总页数】5页(P83-87)
【正文语种】中文
【中图分类】TP311.1
【相关文献】
1.2003年全国程序员考试上午试题评析 [J], 张锦祥
2.程序员资格(水平)考试题例分析 [J], 包红香
3.浅析网络程序员考试中的JavaScript试题 [J], 张锦祥
4."节约型社会"引领"节约型"中考试题——近期节能型中考试题解析 [J], 朱云
5.“节约型社会”引领“节约型”中考试题——近期节能型中考试题解析 [J], 朱云
因版权原因,仅展示原文概要,查看原文内容请购买。
sun公司国际认证试题及答案

sun公司国际认证试题及答案SUN认证是给网络设计界建立的一套认证标准,Sun公司推出了Java以及Solaris技术认证方案。
下面为帮助大家提高对SUN认证的认识,为大家最新的sun公司国际认证试题及答案,希望能帮助到大家!1.Which of the following fragments might cause errors?A. String s = "Gone with the wind";String t = " good ";String k = s + t;B. String s = "Gone with the wind";String t;t = s[3] + "one";C. String s = "Gone with the wind";String standard = s.toUpperCase();D. String s = "home directory";String t = s - "directory";answer:(BD)这道题考察java字符串和连接符+的理解,B中s[3]是一个字符,而不能和一个字符串用连接符连起来。
而D那么是我们初学java时以为有+必定有-,所以导致错误。
java中的连接符只有一个就是+。
而且字符串和字符是两个不同的概念,我们要区分开来。
2. Given the following code fragment:1) public void create() {2) Vector myVect;3) myVect = new Vector();4) }Which of the following statements are true?A. The declaration on line 2 does not allocate memory space for the variable myVect.B. The declaration on line 2 allocates memory space for a reference to a Vector object.C. The statement on line 2 creates an object of class Vector.D. The statement on line 3 creates an object of class Vector.E. The statement on line 3 allocates memory space for an object of class Vectoranswer:(ADE)这题考察获得实例的内存变化。
SUN公司SCJP题库

yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = ;38. double ~temp = ;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.((x==4) && !b2)18. "l ");19. "2 ");20. if ((b2 = true) && b1)21. "3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & ("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. ();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是booleanQuestion 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. "True");14. } else {15. "Not true");16. }17. }18. public Boolean testIfB(String str) {19. return (str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回falseQuestion 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: "three"); break;15. default: "other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. "null");15. } else () == 0) {16. "zero");17. } else {18. "some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime.Answer: D 这题真恶心 15行少个ifQuestion 7Given:x=0;y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:x=12;26. while (x < 10) {27. x--;28. }29. is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; }Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) +" ")15. }‘What is the res ult?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {void foo(int...x) {12. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) for(int z : x) while( ()) ());D. for( int i=0; i< ; i++ ) BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in these ways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. 5));What is the result?A. Line 26 prints "a" to .B. Line 26 prints "b" to .C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line 6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file :1. package ;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. ();7. }8. }and another file, :1. package ;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 inB. add public to the start of line 4 inC. add import .*; at line 2 inD. add import .*; at line 2 inE. add import at line 2 inF. add import line 2 inAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成publicQuestion 19Given:10. package public class Geodetics {12. public static final double DIAMETER = ; }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import class TerraCarta {public double halfway(){ return ; } }B. import static class TerraCarta {public double halfway() { return DIAMETER/; } }C. import static *;public class TerraCarta {public double halfway() { return DIAMETER/; } }D. package class TerraCarta {public double halfway() { return DIAMETER/; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. (bytes);C. import . *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. 3. public class Demo {4. public static void main(String[] args) {5. "pizza"));6. }7. }Which code should be inserted at line 1 of to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import .*;D. static import . *;E. import import static static import F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value of the variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 to suggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling(回收) the memory used by the object rbo?A. ();B. ();C. ();D. ().growHeap();E. ().freeMemory();Answer: A 题很简单。
[IT认证]sun公司认证scjp证书考题模拟试题2
![[IT认证]sun公司认证scjp证书考题模拟试题2](https://img.taocdn.com/s3/m/0d662885a45177232e60a23c.png)
QUESTION 1Exhibit:1.public class SimpleCalc {2.public: int value;3.public void calculate() ( value +- 7; }4 }And:1. public class HuitiCalc extends SiifcpleCalc(public void calculate() { value -* 3; ) public void 2 3 4-5678ealculate(int multiplier) { oail^ulat;supsr.calculate():value *±> multiplier:}publi3 static void iwain(String[ ] args)9. MultiCalc calculator newMultiualc();10.cailculatoi?. calculate( 2 );11.System.out printIn(°Value is: , + calculator value);12.}i*> \What is the result?A. Value is : 8B. Compilation fails.C. Value is : 12D. Value is ; -12E. The code runs with no outputF. An exception is thrown at runtime.Answer:( )QUESTION 2Given the exhibit:20 public clagg Certkiller Card (21.22private String card ID:23pnvale Iritcgi h口it,24public String ov^nerName^25.26 public void set Cardin form st i^n (String c ar dID,27. String o wne rName,28 Integer limit)(29 一this.cardLD= cardlB,30 this J wiietNdiHic —QWticiiTanie^31.thbs.limii =limit;32 }33. }Which statement is true?A. The class is fully encapsulatedB. The code demonstrates polymorphism.C. The ownerName variable breaks encapsulationD. The CardID and limit variables break polymorphismE. The setCardInformation method breaks encapsulationAnswer:( )QUESTION 3Given the exhibit:11 class Animal ( public String noise () ( return "peep"))12.chfs Dog extends Animal (13.public String noist () { return、角clT; }14}15Cat expends A DIHI^I(16.public String noise () { return "mo耻”;)17.} b ■ h h ri30Animal animal =new Dog ();31.Cat cal = (Cat) animal;32.System out.pnntln (Car Noise () )FWhat is the result?A. peepB. barkC. meowD. Compilation fails.E. An exception is thrown at runtimeAnswer:( )QUESTION 4Exhibit:1public class Car {2private int vheelCount;3private String vin (4pub 1 c Car (Str ing vm ) {5this vin = vin:6“this vheelCount - 4;7. )R public Stringextend() {3 return "zoom ^oom *.10- }11public St以ng getlnfo() (12return "WIN: " + vin + * vheels * + vheelCcunt13.)14.}And1public class MeGo ewtends Oar (2public MeGo(String vin)(3this vkeeiCount - 3;4- )5 }What two must the programmer do to oerrect the compilation errors?A. insert a call to this ( ) in the Car CONSTRUCTORB. insert a call to this ( ) in the MeGo constructorC. insert a call to super ( ) in the MeGo constructorD. insert a call to super (vin) in the MeGo constructorE. change the wheel Count variable in CAR TO PROTECTEDF. CHANGE LINE 3 IN THE MeGo class to super wheel Count =3;Answer:( )QUESTION 5Given the exhibit:10interface A { public int gtValue ();)11class B implements A {12.PUBLIC INT GETvALUE () return 1;)B )14.class C extends B (15.// insert code here16’)What three cade inserted mdh Lduallv at line 15. niake use ofWhat three code fragments inserted individually at line 15, make use of polymorphism? (choose three)A. public void add (C c) ( c.getValue ( ); }B. public void add (B b) ( b.getValue ( ); }C. public void add (A a) ( a.getValue ( ); }D. public void add (A a, B b) ( a.getValue ( ); }E. public void add (C c1 C c2) { c1.getV alue ( ); }Answer:( )QUESTION 6Given the exhibit:11 certkilter = new Rs ally Big Object ()t12.// more coce here13.cerftiller = null;14./x insert code here*/Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime ( ) growHeap ()E. Runtime.getRuntime ( ) free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是booleanQuestion 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回falseQuestion 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime. Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached. Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56.Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; }Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]); Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept (接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line 6. Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java Answer: AD 调用不同包下的类,要先导入,方法权限要设置成publicQuestion 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to p rint “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value of the variable (变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 to suggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling (回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。