SCJP认证试题(四)

 /**
*
* @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
*/

[color=red]// Answer : B[/color]

/**
* 注意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
*/

[color=red]// Answer : C[/color]


 /**
*
* @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");
*/

[color=red]// Answer : D E[/color]


 /**
*
* @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);
*/

[color=red]// Answer : C[/color]


/**
*
* @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
*/

[color=red]// Answer : B[/color]


 /**
*
* @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
*/

[color=red]// Answer : C[/color]


 /**
*
* @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
*/

[color=red]// Answer :
// interface Displayable extends Reloadable{
// public void display();
// }[/color]


/**
*
* @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
*/

[color=red]// Answer : D[/color]


 /**
*
* @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
*/
[color=red]
// Answer : B E F
[/color]


/**
*
* @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}
*/

[color=red]// 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){}
// }
//
//
[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值