论坛首页 入门技术论坛

SCJP认证试题(十一)

浏览 2375 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-26  
 /**
 *
 * @author yaoyuan
 */
10	package com.sun.scjp;
11	public class Geodetics{
12		public static final double DIAMETER = 12756.32;  //kilometers
13	}


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 import com.sun.scjp;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}


Answer: A C
/**
*参考静态导入
*/


 /**
 *
 * @author yaoyuan
 */
10	class Line{
11		public static class Point{}
12	}
13	
14	class Triangle{
15		//insert code here
16	}



Which code inserted line 15, 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 in statiated at line 15
D Line l = new Line();  l.Point p = new l.Point();


Answer : B




 /**
 *
 * @author yaoyuan
 */
1	public class Plant{
2		private String name;
3		public Plant(String name){this.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 statement 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

Answer : D



 /**
 *
 * @author yaoyuan
 */

10	public class Bar{
11		static void foo(int x){
12			//insert code here
13		}
14	}


Which two code fragments inserted indepently 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.hashNext()) System.out.println(x.next());
D for(int i=0;i<x.length;i++) System.out.println(x[i]);


Answer : B D


 /**
 *
 * @author yaoyuan
 */

1	class ClassA{
2		public int numberOfInstances;
3		protected ClassA(int numberOfInstances){
4			this.numberOfInstances = numberOfInstances;
5		}
6	}
7	public class ExtendedA extends ClassA{
8		private ExtendedA(int numberOfInstances){
9			super(numberOfInstances);
10		}
11		public static void main(String[] args){
12			ExtendedA ext = new ExtendedA(420);
13			System.out.print(ext.numberOfInstances);
14		}
15	}


Which statement is true?


A 420 is the output
B An exception is thrown at runtime
C All constructors must be declared public
D Constructors cannot use the private modifier
E Constructors cannot use the protected modifier



Answer: A


 /**
 *
 * @author yaoyuan
 */

1	public class Base{
2		public static final String FOO = "foo";
3		public static void main(String[] args){
4			Base b = new Base();
5			Sub s = new Sub();
6			System.out.print(Base.FOO);
7			System.out.print(Sub.FOO);
8			System.out.print(b.FOO);
9			System.out.print(s.FOO);
10			System.out.print(((Base)s).FOO);
11	}}
12	class Sub extends Base{public static final String FOO = "bar";}



What is the result?


A foofoofoofoofoo
B foobarfoobarbar
C foobarfoofoofoo
D foobarfoobarfoo
E barbarbarbarbar
F foofoofoobarbar


Answer: D



/**
*
* @author yaoyuan
*/


Which two statements are true about has-a and is-a relationships?(Choose two)


A Inheritance represents an is-a relationship
B Inheritance repersents an has-a relationship
C Interfaces must be use when creating a has-a relationship
D Instance variables can be used when creating a has-a relationship


Answer:A D


 /**
 *
 * @author yaoyuan
 */

1	package geometry;
2	public class Hypotenuse{
3		public InnerTriangle it = new InnerTriangle();
4		class InnerTriangle{
5			public int base;
6			public int height;
7		}
8	}


Which statement is true about the class of an object that can reference the variable base?


A It can be any class
B No class has access to base
C The class must be long to the geometry package
D The class must be a subclass of the class Hypotenuse



Answer: C


 /**
 *
 * @author yaoyuan
 */

1	interface A{public void aMethod();}
2	interface B{public void bMethod();}
3	interface C extends A,B{public void cMethod();}
4	class D implements B{
5		public void bMethod(){}
6	}
7	class E extends D implements C{
8		public void aMethod(){}
9		public void bMethod(){}
10		public void cMethod(){}
11	}



What is the result?


A Compilation fails because of an error in line 3
B Compilation fails because of an error in line 7
C Compilation fails because of an error in line 9
D if you define D e = new E(),then e.bMethod() invokes the version of bMethod() defined in line 5
E if you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 5
F if you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 9


Answer: F


/**
*
* @author yaoyuan
*/

Which two statements are true?(Choose two)


A An encapsulation,public class promotes re-use
B Classes that share the same interface are always tightly encapsulated
C An encapsulation class allow subclasses to overload methods, but does not allow overriding methods
D An encapsulation class allow programmer to change an implementation without affecting outside code.


Answer:A D




论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics