1public class A{
2 private int counter = 0;
3
4 public static int getInstanceCount(){
5 return counter;
6 }
7
8 public A(){
9 counter++;
10 }
11}
Given this code from class B:
25 A a1 = new A();
26 A a2 = new A();
27 A a3 = new A();
28 System.out.println(A.getInstanceCount());
What is the result?
A Compilation of class A fails
B Line 28 prints the value 3 to System.out
C Line 28 prints the value 1 to System.out
D A runtime error occurs when line 25 executes
E Compilation fails because of an error in line 28
Answer: A
10 class One{
11 void foo(){}
12 }
13 class Two extends One{
14 //insert method here
15 }
Which three methods,inserted individually at line 14, will correctly complete class Two?(Choose three)
A int foo(){/*mode 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*/}
Answer: B C E
1 public interface A{
2 String DEFAULT_GREETING = "Hello World";
3 public void method1();
4 }
A programmer wants to create an interface called B 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{}
Answer : A
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();
Answer: C
Which 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 : A B
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 s 14
B s 16
C s 10
D Compilation fails
E An exception is thrown at runtime
Answer : B
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 : D
11 public class ItemTest{
12 private final int 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?
A Compilation 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
Answer :A
SomeException:
1 public class SomeException{
2 }
Class A:
1 public class A{
2 public void doSomething(){}
3 }
Class B:
1 public class B extends A{
2 public void doSomething(){} throws SomeException;
3 }
Which statement is true about the two classes?
A Compilation of both classes will fail
B Compilation of both classes will succeed
C Compilation of class A will fail. Compilation of class B will succeed
D Compilation of class B will fail. Compilation of class A will succeed
Answer : D
A programmer has an algorithm that requires a java.util.List that privides an
efficient implementation of add(0,object), but does not need to support quick
random access.
what supports these requirements?
A java.util.Queue
B java.util.ArrayList
C java.util.LinearList
D java.util.LinkedList
Answer: D
分享到:
- 2008-11-29 14:30
- 浏览 1987
- 评论(0)
- 论坛回复 / 浏览 (0 / 2044)
- 查看更多
相关推荐
scjp认证试题.rar
scjp模拟试题 scjp模拟试题(一) scjp模拟试题(二) scjp模拟试题(三) CSTP真题.pdf
Java scjp认证考试非常重要的题库,很有用的,
试题,能通过的就去试试吧!scjp试题 java认证考证,最基础的哦!
SCJP认证试题,精典
SUN认证 scjp模拟试题(三)有意向的可以试试
SCJP认证套题解析 SCJP认证套题解析 SCJP认证套题解析
JAVA认证-scjp模拟试题
JAVA认证历年真题 SCJP认证套题60题 含答案和解析
JAVA国际认证(SCJP)典型试题1000例,我花了5个大洋买的电子版,现在上传供各位想考SCJP认证的孩子学习,里面例题由简单到难的。
JAVA认证 scjp模拟试题。。。。
虽然SUN公司被收购了,但它的SCJP认证考试仍在进行中,大家仍可以进行考试,为将来的JAVA之路添砖加瓦!!!
SUN认证的 scjp模拟试题(一),有意向的可以试试
JAVA初级认证考试试题SCJP JAVA初级认证考试试题SCJP
参加sl-275课程培训时老师给的试题 85%以上的覆盖率 这是scjp1.5的试题 它和scjp1.6的试题基本一样
Java国际认证(SCJP)典型试题1000例(中文高清影印版)
Java国际认证(SCJP)典型试题1000例 高清版 pdf 作者: 施铮 出版社: 电子科技大学出版社 出版年: 2005-8 页数: 493 ISBN: 9787810948142
里面有三套模拟试题。sun公司sjcp认证