浏览 1698 次
锁定老帖子 主题:SCJP认证试题(四)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-17
/** * * @author yaoyuan */ 12 public class Certkiller5{ 13 public static void main(String[] yahoo){ 14 for(int x=1;x<yahoo.length;x++){ 15 System.out.print(yahoo[x] + " "); 16 } 17 } 18 } 19 /** *and the command and line invocation java Certkiller5 a b c, What is the result? * * * *A a b *B b c *C a b c *D Compilation fails *E An exception is thrown at runtime */ // Answer : B /** * 注意14行的,x的值 * */ /** * * @author yaoyuan */ 11 public static void certkiller(String str){ 12 int check = 4; 13 if(chect = str.length()){ 14 System.out.print(str.charAt(check = 1) + ""); 15 }else{ 16 System.out.print(str.charAt(0) + ""); 17 } 18 } and the invocation: 13 certkiller("four"); 14 certkiller("tee"); 15 certkiller("to"); /** *What is the result? * * * *A r,t,t *B r,e,o *C Compilation fails *D An exception is thrown at runtime */ // Answer : C /** * * @author yaoyuan */ 11 public class Certkiller{ 12 public static void main(String[] args){ 13 String myProp = /*insert code here*/ 14 System.out.println(myProp); 15 16 /** *and the command line: *java -D rop.custom = gobstopperCertkiller *Which two placed on line 13, will produce the output gobstopper?(choose two) * * *A System.load("prop,custom"); *B System.getenv("prop.custom"); *C System.property("prop.custom"); *D System.getProperty("prop.custom"); *E System.getProperties().getProperty("prop.custom"); */ // Answer : D E /** * * @author yaoyuan */ 1package util; 2public class BitUtils{ 3 public static void process(byte []){/*more code here*/} 4} 1package app; 2public class CertkillerApp{ 3 public static void main(String[] args){ 4 byte[] bytes = new byte[256]; 5 //insert code here 6 } 7} /** *What is required at line 5 in class CertkillerApp to use the process method of BitUtils? * * * *A Process(bytes); *B BitUtils.process(bytes); *C Util.BitUtils.process(bytes); *D CertkillerApp cannot use method in BitUtils *E Import util.BitUtils.*; process(bytes); */ // Answer : C /** * * @author yaoyuan */ public class Item{ private String desc; public String getDescription(){ return desc; } public void setDescription(String d){ desc = 1; } public static void modifyDesc(Item item, String desc){ item = new Item(); item.setDescription(desc); } public static void main(String[] args){ Item it = new Item(); it.setDescription("Gobstopper"); Item it2 = new Item(); it2.setDescription("Fizzylifting"); modifyDesc(it, "Scrumdiddlyumptious"); System.out.println(it.getDescription()); System.out.println(it2.getDescription()); } } /** *What is the out come of the code? * * *A Compilation fails *B Gobstopper * Fizzylifting *C Gobstopper * Scrumdiddlyumptious *D Scrumdiddlyumptious * Fizzylifting *E Scrumdiddlyumptious * Scrumdiddlyumptious */ // Answer : B /** * * @author yaoyuan */ class CertKiller1{ public CertKiller1(){ System.out.print(1); } } class CertKiller2 extends CertKiller1{ public CertKiller2(){ System.out.print(2); } } class CertKiller3 extends CertKiller2{ public CertKiller3(){ System.out.print(3); } } public class Numbers{ public static void main(String[] args){ new CertKiller3(); } } /** *What is the result when this code executed? * * *A 1 *B 3 *C 123 *D 321 *E The code runs with no output */ // Answer : C /** * * @author yaoyuan */ /** *Place the code fragments in position to complete the Displayable interface. */ interface Reloadable{ public void reload(); } class Edit{ public void edit(){ /* Edit Here*/ } } interface Displayable [place here] [place here]{ [place here] } } /** * Code Fragments * * extends public void display(); Reloadable * implements public void display();/"Display"/}; Edit */ // Answer : // interface Displayable extends Reloadable{ // public void display(); // } /** * * @author yaoyuan */ class CertKiller{ public enum Direction{ NORTH,SOUTH,EAST,WEST } public class Sprite{ 14 //insert code here } } /** *Which code ,inserted at line 14, allows the Sprite class to compile? * * *A Direction d = NORTH *B CertKiller.Direction = NORTH *C Direction = Direction.NORTH *D CertKiller.Direction d = CertKiller Direction.NORTH */ // Answer : D /** * * @author yaoyuan */ 10interface Foo{ 11 int bar(); 12} 13 14public class Beta{ 15 16 class A implements Foo{ 17 public int bar(){return 1;} 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(){return 2;} 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) * * *A Compilation fails *B The code compiles and the output is 2 *C If lines 16, 17 and 18 were removed, compilation would fail *D If lines 24,25 and 26 were removed, compilation would fail. *E If lines 16 ,17 and 18 were removed, the code would compiled and the output would be 2 *F If lines 24, 25 and 26 were removed, the code would compiled and the output would be 1 */ // Answer : B E F /** * * @author yaoyuan */ /** *Add methods to the Bate class to make it compile correctly */ class Alpha{ public void bar(int...x){} public void bar(int x){} } public class Beta extends Alpha{ [place here] [place here] [place here] } /** * Methods * * private void bar(int x){} public void bar(int x){} * public int bar(String x){return 1;} public Alpha bar(int x){} * public void bar(int x, int y){} public int bar(int x){return x} */ // Answer : // public class Beta extends Alpha{ // public void bar(int x, int y){} // public int bar(String x){return 1;} // public void bar(int x){} // } // // 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |