当前位置:文档之家› java第二次小测试

java第二次小测试

java第二次小测试
java第二次小测试

Given:

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); //S变为父类,调用父类的函数

11. }

12. }

13. 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

G. foofoofoobarfoo

第32題ABCF

Given:

1. class Mammal{}

2.

3. class Raccoon extends Mammal

4. Mammal m = new Mammal();

5. }

6.

7. class BabyRaccoon extends Mammal{}

Which four statments are true? (Choose four.)

A. Raccoon is-a Mammal.

B. Raccoon has-a Mammal.

C. BabyRaccoon is-a Mammal.

D. BabyRaccoon is-a Raccoon.

E. BabyRaccoon has-a Mammal.

F. BabyRaccoon is-a BabyRaccoon.

Given: //方法重写修饰符不能更私有

2. public class Hi{

3. void m1(){}

4. protected void m2(){}

5. }

6. class Lois extends Hi{

7. //insert code here

8. }

Which four code fragments, inserted independently at line 7, will compile? (Choose four.)

A. public void m1(){}

B. protected void m1(){}

C. private void m1(){}

D. void m2(){}

E. pubic void m2(){}

F. protected void m2(){}

G. private void m2(){}

第34題ACDG

Which four statements are true? (Choose four.)

A. Has-a relationships should never be encapsulated(封装).

B. Has-a relationships should be implemented using inheritance.

C. Has-a relationships can be implemented using instance variables.

D. Is-a relationships can be implemented using the extends keyword.

E. Is-a relationships can be implemented using the implements (继承)keyword.

F. The relationship between Movie and Actress is an example of an is-a relationship.

G. An array or a collection can be used to implement a one-to-many has-a relationship.

第35題 E

Given:

10. public class Hello{

11. String title;

12. int value;

13. public Hello(){ //构造器

14. title += " World";

15. }

16. public Hello(int value){

17. this.value = value;

18. title = "Hello";

19. Hello(); //构造器不能调用可以用super 和this关键字调用

20. }

21. }

and:

30. Hello c = new Hello(5);

31. System.out.print(c.title);

What is the result?

A. Hello

B. Hello World

C. Compilation fails.

D. Hello World 5

E. The code runs with no output.

F. An exception is thrown at runtime.

第36題

Given:

public class Doubler{

public static int doubleMe(Holder h){

return h.getAmount() * 2;

}

}

and:

public class Holder {

int amount = 10;

public void doubleAmount(){amount = Doubler.doubleMe(this);}

public in getAmount(){return amount;}

//more code here

}

Place the code framgmets in position to reduce the coupling between Doubler and Holder. public class Doubler{

public static int doubleMe( Place here h){ //int

return Place here * 2; //h

}

}

public class Holder {

int amount = 10;

public void doubleAmount(){amount = Doubler.doubleMe( Place here );}//amount public in getAmount(){return amount;}

//more code here

}

Code Fragments

void Holder int Doubler

h.getAmount() h this amount

第37題 D

Given:

21. abstract class C1{

22. public C1(){System.out.print(1);}

23. }

24. class C2 extends C1{

25. public C2(){System.out.print(2);}

26. }

27. class C3 extends C2{

28. public C3(){System.out.print(3);}

29. }

30. public class Ctest{

31. public static void main(String[] a){new C3();}

32. }

What is the result?

A. 3

B. 23

C. 32

D. 123

E. 321

F. Compilation fails.

G. An exception is thrown at runtime.

第38題CD

Given:

1. class One{

2. public One foo(){return this;}

3. }

4. class Two extends One{

5. public One foo(){return this;}

6. }

7. class Three extends Two{

8. //insert method here

9. }

Which two methods, inserted individually, correctly complete the Three class? (Choose two.)

A. public void foo(){}

B. public int foo(){return 3;}

C. public Two foo(){return this;}

D. public One foo(){return this;}

E. public Object foo(){return this;}

第39題ABCE

Given:

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;} //方法内不能给final直接赋值

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. }

Which four statments are true? (Choose four.)

A. Compilation fails.

B. An exception is thrown at runtime.

C. The attribute id in the ItemTest object remains unchanged.

D. The attribute id in the ItemTest object is modified to the new value.

E. A new ItemTest object is created with the preferred value in the id attribute.

第40題 B

Given:

1. class Foo{

2. private int x;

3. public Foo(int x){this.x = x;}

4. public void setX(int x){this.x = x;}

5. public int getX(){return x;}

6. }

7.

8. public class Gamma{

9. static Foo fooBar(Foo foo){

10. foo = new Foo(100);

11. return foo;

12. }

13. public static void main(String[] args){

14. Foo foo = new Foo(300);

15. System.out.print(foo.getX() + "-");

16.

17. Foo fooFoo = fooBar(foo);

18. System.out.print(foo.getX() + "-");

19. System.out.print(fooFoo.getX() + "-");

20.

21. foo = fooBar(fooFoo);

22. System.out.print(foo.getX() + "-");

23. System.out.print(fooFoo.getX());

24. }

25. }

What is the output?

A. 300-100-100-100-100

B. 300-300-100-100-100

C. 300-300-300-100-100

D. 300-300-300-300-100

第41題 D

Given:

1. public class KungFu{

2. public static void main(String[] args){

3. Integer x = 400; //integer 在-128~127以外new

4. Integer y = x;

5. x++;

6. StringBuilder sb1 = new StringBuilder("123");

7. StringBuilder sb2 = sb1; //s1 new了一个新空间s1 s2同时指向这个空间.method后new空间的值变化二者同时变

8. sb1.append("5");

9. System.out.println((x == y) + " " + (sb1 == sb2));//s1只要变s2跟着变

10. }

11. }

What is the result?

A. true true

B. false true

C. true false

D. false false

E. Compilation fails.

F. An exception is thrown at runtime.

第42題

1. 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 runtime.

D. Compilation of class A will fail due to an error in line 6.

第43題 D

Given:

1. class Plant{

2. private String name;

3. public Plant(String name){https://www.doczj.com/doc/7517236477.html, = name;}

4. public String getName(){return name;}

5. }

6. public class Tree extends Plant{

7. public void growFruit(){}

8. public void dropLeaves(){}

9. }

What 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.

第44題AE

Given:

1. class Employee{

2. String name; double baseSalary;

3. public Employee(String name, double baseSalary){

4. https://www.doczj.com/doc/7517236477.html, = name;

5. this.baseSalary = baseSalary;

6. }

7. }

8. public class SalesPerson extends Employee{

9. double commission;

10. public SalesPerson(String name,

11. double baseSalary, double commission){

12. //insert code here

13. }

14. }

Which two code fragments, inserted independently at line 12, will compile? (Choose two.)

A. super(name, baseSalary);

B. https://www.doczj.com/doc/7517236477.html,mission = commission;

C. super();

https://www.doczj.com/doc/7517236477.html,mission = commission;

D. https://www.doczj.com/doc/7517236477.html,mission = commission;

super();

E. super(name, baseSalary);

https://www.doczj.com/doc/7517236477.html,mission = commission;

F. https://www.doczj.com/doc/7517236477.html,mission = commission;

super(name, baseSalary);

G. super(name, baseSalary, commission);

第45題AC

Given that:

Gadget has-a Sprocket and

Gadget has-a Spring and

Gadget is-a Widget and

Widget has-a Sprocket

Which two code fragments represent these relationships? (Choose two.)

A. class Widget{Sprocket s;}

class Gadget extends Widget{Spring s;}

B. class Widget{}

class Gadget extends Widget{Spring s1; Sprocket s2;}

C. class Widget{Sprocket s1; Spring s2;}

class Gadget extends Widget{}

D. class Gadget{Spring s;}

class Widget extends Gadget{Sprocket s;}

E. class Gadget{}

class Widget extends Gadget{Sprocket s1; Spring s2;}

F. class Gadget{Spring s1; Sprocket s2;}

class Widget extends Gadget{}

第46題 C

Given:

10. public class Pizza{

11. ArrayList toppings;

12.

13. public final void addTopping(String topping){

14. toppings.add(topping);

15. }

16.

17. public void removeTopping(String topping){

18. toppings.remove(topping);

19. }

20. }

And:

30. class PepperoniPizza extends Pizza{

31. public void addTopping(String topping){

32. System.out.println("Cannot add Toppings");

33. }

34.

35. public void removeTopping(String topping){

36. System.out.println("Cannot remove pepperoni");

37. }

38. }

And:

50. Pizza pizza = new PepperoniPizza();

51. pizza.addTopping("Mushrooms");

52. pizza.removeTopping("Pepperoni");

What is the result?

A. Compilation fails.

B. Cannot add Toppings

C. The code runs with no output.

D. A NullPointerException is thrown in Line 4.

第48題 E

Given:

1. public class Venus{

2. public static void main(String[] args){

3. int[] x = {1, 2, 3};

4. int y[] = {4, 5, 6};

5. new Venus().go(x, y);

6. }

7. void go(int[]... z){ //代表多个一维数组

8. for(int[] a : z)

9. System.out.print(a[0]);

10. }

11. }

What is the result?

A. 1

B. 12

C. 14

D. 123

E. Compilation fails.

F. An exception is thrown at runtime.

第49題

Place code framgmets into position so the output is: The quantity is 420 Place here update(int quantity, int adjust){

Place here

}

public void callUpdate(){

int quant = 100;

Place here

System.out.println("The quantity is " + quant);

}

Code Fragments

public int quantity = quantity + adjust; update(quant, 320); public void quant = update(quant, 320);

quantity = quantity + adjust;

return quantity;

第50題DE

Given:

1. public abstract class Shape{

2. private int x;

3. private int y;

4. public abstract void draw();

5. public void setAnchor(int x, int y){

6. this.x = x;

7. this.y = y;

8. }

9. }

Which two classes use the Shape class correctly? (Choose two.)

A. public class Circle implements Shape{

private in radius;

}

B. public abstract class Circle extends Shape{

private in radius;

}

C. public class Circle extends Shape{

private in radius;

public void draw();

}

D. public abstract class Circle implements Shape{

private in radius;

public void draw();

}

E. public class Circle extends Shape{

private in radius;

public void draw(){/* code here */}

}

F. public abstract class Circle implements Shape{

private in radius;

public void draw(){/* code here */}

}

第51題 A

Given:

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 here

4. }

5.

6. public String execute(){

7. //more code here

8. }

9. }

1. public class C extends B{

2. public AImpl doit(){

3. //more code here

4. }

5.

6. public Object execute(){

7. //more code here

8. }

9. }

Which statement is true about the classes and interfaces?

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.

第54題 A

Given:

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 class

B. only the Target class

C. any class in the test package

D. any class that extends Target

第55題 D

Given:

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, 0

B. 150, 60, 0

C. Compilation fails.

D. 150, 150, 150 、//徐方法调用

E. An exception is thrown at runtime.

第56題 C

Given:

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.

第57題 D

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;} //country是父类私有的不能调用只能调用方法

27. }

28. public class Euro extends Money{

29. public String getC(){return super.getC();}

30. public static void main(String[] args){

31. System.out.print(new Yen().getC() + " " + new Euro().getC());

32. }

33. }

What is the result?

A. Canada

B. null Canada

C. Canada null

D. Canada Canada

E. Compilation fails due to an error on line 26.

F. Compilation fails due to an error on line 29.

第58題 B

Given:

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 here

17. }

18. }

Which code, inserted at line 16, will cause a https://www.doczj.com/doc/7517236477.html,ng.ClassCastException?

A. Alpha a = x;

B. Foo f = (Delta)x; //不能转换为子类

C. Foo f = (Alpha)x;

D. Beta b = (Beta)(Alpha)x;

第59題 D

Given the following directory structure:

bigProject //包

|--source //

| |--Utils.java

|

|--classes

|

And the following command line invocation:

javac –d classes source/Utils.java

Assume the current directory is bigProject, what it 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.

第61題 C

Given two files, GrizzlyBear.java and Salmon.java:

1. package animals.mammals;

2.

3. public class GrizzlyBear extends Bear{

4. void hunt() {

5. Salmon s = findSalmon();

6. s.consume();

7. }

8. }

1. package animals.fish;

2.

3. public class Salmon extends Fish {

4. public void consume() { /* do stuff */ }

5. }

If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?

A. add import animals. mammals.*; at line 2 in Salmon.java

B. add import animals.fish.*; at line 2 in GrizzlyBearjava

C. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java

D. add import animals. mammals.GrizzlyBear*; at line 2 in Salmon.java

第62題 C

Given:

31. class Foo{

32. public int a = 3;

33. public void addFive(){ a += 5; System.out.print("f "); }

34. }

35. class Bar extends Foo{

36. public int a = 8;

37. public void addFive(){this.a += 5; System.out.print("b ");} //this调用当前的a=8

38. }

Invoked with:

Foo f = new Bar();

f.addFive();

System.out.println(f. a);

What is the result?

A. b 3

B. b 8

C. b 13

D. f 3

E. f 8

F. f 13

G. Compilation fails,

H. An exception is thrown at runtime.

第63題CEF

Given:

11. class ClassA{}

12. class ClassB extends ClassA{}

13. class ClassC extends ClassA{}

and:

21. ClassA p0 = new ClassA();

22. ClassB p1 = new ClassB();

23. ClassC p2 = new ClassC();

24. ClassA p3 = new ClassB();

25. ClassA p4 = new ClassC();

Which three are valid? (Choose three.)

A. p0 = p1; //对象之间的赋值

B. p1 = p2,

C. p2 = p4;

D. p2 = (ClassC)p1;

E. p1 = (ClassB)p3;

F. p2 = (ClassC)p4;

第64題AA BA

Given:

class A {

String name = "A";

String getName() {

return name;

}

String greeting(){

return "class A";

}

}

class B extends A {

String name = "B";

String greeting() {

return "class B";

}

}

public class Client {

public static void main( String[] args ) {

A a = new A();

A b = new B();

System.out.println(a.greeting() + "has name" + a.getName());

System.out.println(b.greeting() + "has name" + b.getName());

}

}

Place the names "A" and "B" in the following output Names

class Place here has name Place here

class Place here has name Place here

Names

A B

第65題

Replace two of the Modifiers that appear in the Single class to make the code compile.

Note: Three modifiers will not be used and four modifiers in the code will remain unchanged.

Code

public class Single {

private static Single instance;

public static Single getInstance() {

if (instance == null) instance = create(); //静态方法必须调用静态方法

return instance;

}

private Single() { } //PROTECTED

protected Single create() { return new Single(); } //+static

}

class SingleSub extends Single {

}

Modifiers

final

protected

private

abstract

static

第66題AF

Given:

5. class Thingy{ Meter m = new Meter(); }

6. class Component {void go() { System.out.print("c");}}

7. class Meter extends Component {void go() { System.out.print("m"); }}

8.

9. class DeluxeThingy extends Thingy {

10. public static void main(String[] args) {

11. DeluxeThingy dt = new DeluxeThingy();

12. dt.m.go();

13. Thingy t = new DeluxeThingy();

14. t.m.go();

15. }

16. }

Which two are true? (Choose two.)

A. The output is mm.

B. The output is mc.

C. Component is-a Meter.

D. Component has-a Meter.

E. DeluxeThingy is-a Component.

F. DeluxeThingy has-a Component.

第67題AB

Given:

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 here

18. }

Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)

A. double getSalesAmount() { return 1230.45; }

B. public double getSalesAmount() { return 1230.45; }

C. private double getSalesAmount() { return 1230.45; }

D. protected double getSalesAmount() { return 1230.45; }

第69題ABD

Given

11. public interface Status {

12. /* insert code here */ int MY_VALUE = 10;

13. }

Which three are valid on line 12? (Choose three.)

A. final

B. static

C. native

D. public

E. private

F. abstract C. protected

java基础测试题

一、选择题48分每题2分 1.面向对象的三大特性不包括() A 封装 B 继承 C 多态 D 消息通信 2.下列声明哪个是错误的() A int i = 10; B float f = 1.1; C double d = 34.4; D long m = 4990; 3.程序的执行结果是() public class Test { public static void main(String [] args){ System.out.println(“”+'a'+1); } } A 98 B a 1 C 971 D 197 4.程序的执行结果是() public class Test { int x; public static void main(String [] args){ Test t = new Test(); t.x=5; change(t); System.out.println(t.x); } public static void change(Test t){ t.x=3; } } A 5 B 3 C 编译出错 D 以上答案都不对 5.关于类与对象说法错误的是() A 类是模板,对象是产品 B 人是类,男人是对象 C 类是对某一事物的描述是抽象的,对象是实际存在的该类事物的个体 D 汽车设计图是类,制造的若干汽车是对象 6.关于构造函数说法错误的是() A 构造函数名与类相同 B 构造函数无返回值,可以使用void 修饰 C 构造函数在创建对象时被调用 D 在一个类中如果没有明确的给出构造函数,编译器会自动提供一个构造函数7.程序的执行结果是() public class Test { public static void main(String [] args){ String str1= new String("abc"); String str2 = new String("abc"); String str3=str1; if(str1.equals(str2)){ System.out.println("true"); }else{ System.out.println("false"); } if(str1==str3){

java基础练习题

1) 以下关于Java语言说法错误的是()。(选择两项) a) Java语言是一种OO语言,Java API是Java语言的帮助文档 b) Java语言具有平台无关性-Write Once,Run Anywhere c) Java语言的核心是Java Virtual Machine d) 使用Java语言,程序员要使用原始方法分配和释放内存空间 e) Java语言是一种编译执行语言 知识点: 第一章Java语言基础Java语言基本概念 2) 以下哪一项不是Java的关键字(b)。(选择一项) a) if b) then c) goto d) case e) while 知识点: 第二章Java编程基础Java中的关键字 3) 下列(a,e)不是合法的Java语言标识符。(选择两项) a) 2variable b) variable2 c) _whatavariable d) $anothervar e) #myvar f) _3_ 知识点: 第二章Java编程基础Java中的标识符 4) 执行下列代码段后,变量x的值是(c)。(选择一项) x=9; y=9; x=(y<=x++)?1:0; a) 1 b) 2 c) 0 d) 10 知识点: 第二章Java编程基础三元运算符 5) System.out.println(4 | 7);上面语句的输出结果是(d)。(选择一项) a) 4 b) 5 c) 6 d) 7 e) 0 知识点: 第二章Java编程基础位运算符 6) 以下会产生编译错误的Java语句是(b)。(选择一项) a) if (2 == 3) System.out.println("Hi"); b) if (2 = 3) System.out.println("Hi");

Java基础笔试机试测试题(带答案)

Java基础考试题 班级:__________ 姓名:___________ 日期:_____________ 一、笔试(45题,每题2分) 1) 分析下面的Java程序段,编译运行后的输出结果是()。 public class Test { public static void changeString(StringBuffer sb) { sb.append("stringbuffer2"); } public static void main(String[] args) { StringBuffer sb = new StringBuffer("stringbuffer1"); changeString(sb); System.out.println("sb = " + sb.toString()); } } A. sb = stringbuffer2stringbuffer1 B. sb = stringbuffer1 C. sb = stringbuffer2 D. sb = stringbuffer1stringbuffer2 2) 在Java中,包有多种用途,但不包含()。 A. 将类组合成较小的单元,便于使用 B. 有助于避免命名冲突 C. 有助于提高运行效率 D. 允许在更广的范围内保护类、数据和方法 3) 在Java中,如果要在字符串类型s="java" 中,得到字母'v' 出现的位置,选()语句。 A)s.matches('v'); B)s.charAt('v'); C)s.indexOf('v'); D)s.substring('v'); 4)下列代码运行后,变量 c 的值是()。 int a=15,b=10; double c=a/b; a) 1.5 b) 1.0 c) 1 d) 0 5)main 方法如下所示,该程序的运行结果是()。 public static void main(String [] args){ int i=0; System.out.print(i++); } a) 输出0 b) 输出1 c) 编译错误d) 运行时出现异常

java基础测试题及答案

、选择题(每题 2 分,共40 分) 1、下面哪个是Java 语言中正确的标识符( C ) A、3com B 、import C、that D、this 2、下面哪个语句(初始化数组)是不正确的: ( B ) A.int x[] = {1,2,3}; B .int x[3] = {1,2,3}; C.int[] x = {1,2,3}; D .int x[] = new int[]{1,2,3}; 3、下述概念中不属于面向对象方法的是( D ) 。 A. 对象、消息??B?继承、多态? ?? C.类、封装? ??? D .过程调用 4、下面的代码段中,执行之后i 和j 的值是什么? ( B ) int i = 1; int j; j = i++*2+3*--i; A . 1, 2 B . 1, 5 C . 2, 1 D . 2, 2 5、下面哪条语句把方法声明为抽象的公共方法?( B ) A. public abstract method(); B. public abstract void method(); C. public abstract void method(){} D. public void method() extends abstract;

6、下面关于java 中类的说法哪个是不正确的?( C ) A. 类体中只能有变量定义和成员方法的定义,不能有其他语句。 B. 构造函数是类中的特殊方法。 C?类一定要声明为public的,才可以执行。 D. —个java文件中可以有多个class定义。 7、假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的? ( C ) class A { int i; static String s; void method1() { } static void method2() { } } A、; B 、(); C. (); D 、() 8、容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改 变?( B ) A、CardLayout B 、FlowLayout C 、BorderLayout D 、GridLayout 9、下列哪个用户图形界面组件在软件安装程序中是常见的? ( C ) A.滑块 B. 进度条 C.按钮 D. 标签

最新Java基础试题及其答案

Java试题 一单项选择 1)在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,这个类必须定义为()。() a)protected b)private c)public d)friendly 2)在Java中,下列()语句不能通过编译。(选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; c) int a= 3+5 d) float f=5+5.5; 3)给定java代码如下,运行时,会产生()类型的异常。(选择一项) String s=null; s.concat(“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 4) 在java中,()对象可以使用键/值的形式保存数据。(选择一项) a)ArrayList b) HashSet c) HashMap d) LinkedList 5)给定如下java代码,编译运行之后,将会输出()。 public class Test{ public staticvoid main(String args[]){ int a=5; System.out.println(a%2==1) ?(a+1) /2:a/2) ; } } (选择一项) a)1 b)2 c)2.5 d)3 6)以下Java语句中,String str = “123456789”;str =str.subString(1,3);执行后str中的值为。(选择一项) a) “23” b)“123”

Java基础试题及其答案

J a v a基础试题及其答案 The latest revision on November 22, 2020

Java试题 1) java程序中,main方法的格式正确的是()。(选择一项) a)static void main(String[] args) b)public void main(String[] args) c)public static void main(String[]s) d)public static void main(String[] args) 2)给定java代码,如下: public byte count(byte b1,byte b2){ return______; } 要使用这段代码能够编译成功,横线处可以填入()。(选择一项) a)(byte) (b1-b2) b)(byte) b1-b2 c) b1-b2 d) (byte) b1/b2 3)在Java中,在包下定义一个类,要让包下的所有类都可以访问这个类,这个类必须定义为()。(选择一项) a)protected b)private c)public d)friendly 4)在Java中,下列()语句不能通过编译。 (选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; “”+new Person() toString() c) int a= 3+5 d) float f=5+; double float 6)给定java代码如下,运行时,会产生()类型的异常。(选择一项) String s=null; (“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 已到文件尾,再读取抛出 7) 在java中,()对象可以使用键/值的形式保存数据。(选择一项) a)ArrayList List 有序可重复 b) HashSet Set 无序不可重复同一对象是重复的 c) HashMap Map(key/value)重复定义:hashCode、equals(业务) d) LinkedList List 8)给定如下java代码,编译运行之后,将会输出()。 public class Test{ public static void main(String args[]){ int a=5; Sys((a%2==1) (a+1) /2:a/2) ;三目表达式 } } (选择一项) a)1 b)2

50道JAVA基础编程练习题

50道JAVA基础编程练习题 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一 对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析:兔子的规律为数列1,1,2,3,5,8,13,21.... 【程序2】 题目:判断101-200之间有多少个素数,并输出所有素数。 1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。 【程序3】 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。 1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。 【程序4】 题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成: (1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。 (2)如果n<>k,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数你n,重复执行第一步。 (3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。 【程序5】 题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下 的用C表示。 1.程序分析:(a>b)?a:b这是条件运算符的基本例子。 【程序6】 题目:输入两个正整数m和n,求其最大公约数和最小公倍数。 1.程序分析:利用辗除法。

java基础测试题_含答案

姓名 一、选择题(每题2分,共30分) 1.请写出标识符的命名规则描述正确的是[多选]( ABCD ) A、由英文字母、数字、_和$组成,长度不限。 B、标识符的第一个字符不能是数字 C、标识符区分大小写。 D、标识符不能包含空格。 2. 下列属于正确标识符的选项有[多选](BDGH) A. int B. $_Count C. 3M D. Hello E. b-7 F. ms#d G. bool H. D9658 3、下列哪一个不属于java的基本类型( B ) A、int B、String C、float D、byte 4、下列那条语句能编译通过( A ) A、String String=”String”; B、float float=””; C、int int = 11; D、int i= ; 5、下列代码的执行结果是: ( D ) public class Test1{ public static void main(String args[]){ float t=; int q=5; }

} A、 40 B、 C、36 D、 6、int长度描述正确的是( A ) A、-2^31到2^31 - 1 B、-2^32到2^32 - 1 C、-2^7到2^7 - 1 D、-2^8到2^8 - 1 7、关于==和equals方法描述不正确的是( D ) A、==是运算符、equals是方法 B、==只比较对象,equals会先比较对象,如果不是一个对象,会对对象的值进行比较。 C、String a= "1"; String b= "1"; 输出结果为:true D、String a=new String("1");String b=new String("1"); 输出结果为:true 8、下列关于哪个不属于java的特性( D ) A、封装 B、继承 C、多态 D、重载 9、某一个子类要继承一个父类,要使用关键字( B ) A、import B、extends C、implements D、java 10、某一个子类要实现一个父接口,要使用关键字( C ) A、import B、extends C、implements D、java 11、以下关于接口和类的说法正确的是( C ) A、接口和类都可以实现多重继承 B、子类可以继承多个父类 C、子类可以实现多个接口 D、一个子类不能同时继承某一个父类和实现某一个接口 12、一个非抽象子类,如果要实现某个接口,则( A ) A、必须实现该接口中的所有抽象方法 B、可以实现部分抽象方法 C、可以不实现任何抽象方法

Java基础测试题

Ps:答案已写在上面。希望大家把其他错误选项问题找出来. 第一组: 1.下面哪些是合法的变量名 (DEG) A.2variable .variable2 ._whatavariable $_¥ 2.请问“abcd” instanceof Object返回的值是 (B) A. “abcd” B. true C. false D. String 前面是后面的子类 面说法正确的是:(A) A. 如果源代码中有package语句,则该语句必须放在代码的第一行(不考虑注释和空格); B. 如果源代码中有import语句,则该语句必须放在在代码的第一行(不考虑注释和空格)如果源代码中有main()方法,则该方法必须被放在代码的第一行如果某文件的源代码中定义了一个public 的接口,接口名和文件名可以不同。 4.下面有关方法覆盖说法不正确的是:(B) A. 方法覆盖要求覆盖和被覆盖的方法有相同的名字,参数列以及返

回值 B. 方法覆盖要求覆盖和被覆盖的方法必须具有相同的访问权限; C. 覆盖的方法不能比被覆盖的方法抛出更多的异常 D. 覆盖的方法一定不能是private的 5.一个Java程序运行从上到下的环境次序是(C) A. 操作系统、Java程序、JRE/JVM、硬件 B. JRE/JVM、Java程序、硬件、操作系统 C. Java程序、JRE/JVM、操作系统、硬件 D. Java程序、操作系统、JRE/JVM、硬件 6. 下面选项中哪个关键字可以用来修饰接口中的变量和方法(A) A. static B. private C. synchronized D. protected 7. 下面代码段中:(A) String String=”String”; String B. 不知道 C. 编译出错 D. 运行出错 8. 下面哪种是正确的创建Map集合的方式:(D) A. Map m=new Map();

java基础测试题及答案

一、选择题(每题2分,共40分) 1、下面哪个是Java语言中正确的标识符( C ) A、3com B、import C、that D、this 2、下面哪个语句(初始化数组)是不正确的:( B) A.int x[] = {1,2,3}; B.int x[3] = {1,2,3}; C.int[] x = {1,2,3}; D.int x[] = new int[]{1,2,3}; 3、下述概念中不属于面向对象方法的是( D )。 A.对象、消息 B.继承、多态 C.类、封装 D.过程调用 4、下面的代码段中,执行之后i 和j 的值是什么? ( B ) int i = 1; int j; j = i++*2+3*--i; A.1, 2 B.1, 5 C. 2, 1 D. 2, 2 5、下面哪条语句把方法声明为抽象的公共方法?( B ) A.public abstract method(); B.public abstract void method(); C.public abstract void method(){} D.public void method() extends abstract; 6、下面关于java中类的说法哪个是不正确的?( C ) A.类体中只能有变量定义和成员方法的定义,不能有其他语句。 B.构造函数是类中的特殊方法。 C.类一定要声明为public的,才可以执行。 D.一个java文件中可以有多个class定义。 7、假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的?( C ) class A { int i; static String s; void method1() { } static void method2() { } } A、System.out.println(a.i); B、a.method1(); C、A.method1(); D、A.method2() 8、容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小 的变化而改变? ( B ) A、 CardLayout B、 FlowLayout C、 BorderLayout D、 GridLayout 9、下列哪个用户图形界面组件在软件安装程序中是常见的? ( C )

java基础测试题-含答案

Java基础试题 姓名 一、选择题(每题2分,共30分) 1.请写出标识符的命名规则描述正确的是[多选](ABCD ) A、由英文字母、数字、_和$组成,长度不限。 B、标识符的第一个字符不能是数字 C、标识符区分大小写。 D、标识符不能包含空格。 2. 下列属于正确标识符的选项有[多选](BDGH) A. int B. $_Count C. 3M D. Hello E. b-7 F. ms#d G. bool H. D9658 3、下列哪一个不属于java的基本类型( B ) A、int B、String C、float D、byte 4、下列那条语句能编译通过( A ) A、String String=”String”; B、float float=”3.14”; C、int int = 11; D、int i= 1.1; 5、下列代码的执行结果是: ( D ) public class Test1{ public static void main(String args[]){

float t=9.0f; int q=5; System.out.println((t++)*(--q)); } } A、40 B、40.0 C、36 D、36.0 6、int长度描述正确的是( A ) A、-2^31到2^31 - 1 B、-2^32到2^32 - 1 C、-2^7到2^7 - 1 D、-2^8到2^8 - 1 7、关于==和equals方法描述不正确的是( D ) A、==是运算符、equals是方法 B、==只比较对象,equals会先比较对象,如果不是一个对象,会对对象的值进行比较。 C、String a= "1"; String b= "1"; System.out.println(a==b); 输出结果为:true D、String a=new String("1");String b=new String("1"); System.out.println(a==b);输出结果为:true 8、下列关于哪个不属于java的特性( D ) A、封装 B、继承 C、多态 D、重载 9、某一个子类要继承一个父类,要使用关键字( B ) A、import B、extends C、implements D、java 10、某一个子类要实现一个父接口,要使用关键字( C ) A、import B、extends C、implements D、java 11、以下关于接口和类的说法正确的是( C )

Java基础试题及其答案

Java试题 1) java程序中,main方法的格式正确的是()。(选择一项) a)static void main(String[] args) b)public void main(String[] args) c)public static void main(String[]s) d)public static void main(String[] args) 2)给定java代码,如下: public byte count(byte b1,byte b2){ return______; } 要使用这段代码能够编译成功,横线处可以填入()。(选择一项) a)(byte) (b1-b2) b)(byte) b1-b2 c) b1-b2 d) (byte) b1/b2 3)在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,这个类必须定义为()。(选择一项) a)protected b)private c)public d)friendly 4)在Java中,下列()语句不能通过编译。(选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; c) int a= 3+5 d) float f=5+5.5; 5) 在Java中下列()方法可以把JFrame的布局管理器设为FlowLayout类型(选择一项) a)jFrame.setLayout(new FlowLayout() ); b) jFrame.addLayout(new FlowLayout() ) c)jFrame.setFlowLayout() d)jFrame.addFlowLayout() 6)给定java代码如下,运行时,会产生()类型的异常。(选择一项) String s=null; s.concat(“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 7) 在java中,()对象可以使用键/值的形式保存数据。(选择一项) a)ArrayList b) HashSet c) HashMap d) LinkedList

Java基础习题(含答案)

的Java基础习题(附答案)1 收藏 1.下列语句序列执行后,m 的值是( C)。 int a=10, b=3, m=5; if( a==b ) m+=a; else m=++a*m; A) 15 B) 50 C) 55 D) 5 2.下列语句序列执行后,k 的值是(B )。 int i=4,j=5,k=9,m=5; if(i>j||mj||m

java基础测试题(一)

1. (2.0 分) 下面关于 JAVA 的优点说法错误的是?
JAVA 是纯面向对象的语句,还有众多的 API 支持,所以 JAVA 开发各种各样的应用 程序变的非常容易且易于维护。 B、JAVA 使用的是 Unicode 作为标准字符,这使得 JAVA 程序在不同的语言平台上 都能被编译和运行 JAVA 引进来的 EXCEPTION 处理机制,使得 JAVA 程序更安全、更稳定、更随机应 变 垃圾回收机制是 JAVA 的内在特性,垃圾回收机制的调度是由程序员负责的
2. (2.0 分) 下面说法正确的是?
当运行 Javac 命令对一个 Java 源程序(.java)进行编译时,必须写出该源文件的完 当运行 Javac 命令对一个 Java 源程序(.java)进行编译时,不必写出该源文件的扩 展名.java 当用 Java 命令解析运行一个 class 文件时,必须写出该 class 文件的扩展名.class 无论运行 Javac 还是 Java 命令,后面的源文件都必须给出文件扩展名
3. (2.0 分) Java 语言具有许多优点和特点,下列选项中,哪个反映了 Java 程序并行机 制的特点
安全性 多线程 跨平台 可移植

4. (2.0 分) 如下哪些字串是 Java 中的合法标识符。
field super 3number #number
5. (2.0 分) java 对类名有严格的要求,下列中说法正确的是
类名首字母必须大写 类名必须与它说在的文件名相同 类名不容许出现数字 类名长度不得大于 32 个字符
6. (2.0 分) java 中的 char 类型的字节长度是
8 16 32 依平台而定

java基础考试题及答案

一、选择题(共30题,每题2分) 1.下面哪些是合法的标识符(多选题) A. $persons B. TwoUsers C. *point D. this E. _endline 答案A,B,E 分析Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字(this保留字)。 2.哪些是将一个十六进制值赋值给一个long型变量(单选题) A. long number = 345L; B. long number = 0345; C. long number = 0345L; D. long number = 0x345L 答案 D 分析十六进制数以0x开头,long型数以L(大小写均可,一般使用大写,因为小写

的l和数字1不易区分)。 3.下面的哪些程序片断可能导致错误(多选题) 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 = (); D. String s = "home directory"; String t = s - "directory"; 答案B,D 分析 A:String类型可以直接使用+进行连接运算。 B:String是一种Object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误。

JAVA基础考试题

1704班基础考试题 1、下列关于java中抽象类的说法正确的有(A) A、含有抽象方法的类必须声明为抽象类 B、抽象类中不可以有非抽象方法 C、抽象类中至少需要包含一个抽象方法 D、抽象类无法实例化 2、下列哪个关键字可以用于实现同步(C) A、native B、static C、synchronized D、finalize 3、下列哪些集合属于Collection的子类(C D)[选两项] A、TreeMap B、Hashtable C、ArrayList D、HashSet 4、下面关于线程的说法错误的是(B) A、线程其实就是进程中的一个控制单元,它负责就是程序的执行。一个进程中至少有一个线程 B、当一个类实现了Runnable接口后,并实现了其run方法,就可以直接调用这个类的start方法开启线程

C、继承Thread类或者实现Runnable接口都可以封装线程要执行 的任务 D、Thread类本身就是一个线程类,可以直接创建Thread类对象,开启线程 5、下面关于map集合说法正确的是(A) A、map集合中不能直接使用Iterator进行迭代 B、对map集合使用keySet方法,会得到所有value的值组成一个list集合 C、使用map的append方法可以向map集合中添加元素 D、使用removeAll方法可以将map集合中的元素清空 6、下面的程序执行后count的结果是(B) A、0 B、10 C、9 D、11 7、关于被私有访问控制符private修饰的成员变量,以下说法正确的是(C) A、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类 B、可以被两种类访问和引用:该类本身、该类的所有子类 C、只能被该类自身所访问和修改 D、只能被同一个包中的类访问

Java基础测试题(答案)

1. 有以下程序片段,下列哪个选项不能插入到行1。( D ) 1. 2.public class Interesting{ 3.//do sth 4. } (只能有一个public修饰的class) A、import java.awt.*; B、package mypackage; C、class OtherClass{ } D、public class MyClass{ } 2. 以下哪项是接口的正确定义?( B D ) A、interface B { void print(){};} (接口里的方法都是抽象的,不能有方法体) B、abstract interface B { void print() ;} C、abstract interface B extends A1,A2 //A1、A2为已定义的接口 { abstract void print(){ };} (同上) D、interface B { void print();} 1.接口可以声明为public(公共)或默认的访问权限。接口隐含表明是抽象的(abstract)的。 2.接口的方法默认即为public(公共)且是abstract(抽象)的. 3.接口中的变量默认即为public(公共), static(静态) and final(最终的)。 接口声明编译器如何解释呢 public interface Searchable {}public abstract interface Searchable {} abstract interface Searchable {}abstract interface Searchable {} interface Searchable {}abstract interface Searchable {}

java基础测试卷

JA V A面试基础测试题 注意:(1)请在答题纸上写好你的名字、面试日期、手机号码 (2)请将答案写在答题纸上,不要在试卷上答题或者弄脏试卷 (3)试题共100分,题量比较大,请在60分钟内尽可能多的答题 一、选择题48分每题2分 1.面向对象的三大特性不包括() A 封装 B 继承 C 多态 D 消息通信 2.下列声明哪个是错误的() A int i = 10; B float f = 1.1; C double d = 34.4; D long m = 4990; 3.程序的执行结果是() public class Test { public static void main(String [] args){ System.out.println(“”+'a'+1); } } A 98 B a 1 C 971 D 197 4.程序的执行结果是() public class Test { int x; public static void main(String [] args){ Test t = new Test(); t.x=5; change(t); System.out.println(t.x); } public static void change(Test t){ t.x=3; } } A 5 B 3 C 编译出错 D 以上答案都不对 5.关于类与对象说法错误的是() A 类是模板,对象是产品 B 人是类,男人是对象 C 类是对某一事物的描述是抽象的,对象是实际存在的该类事物的个体 D 汽车设计图是类,制造的若干汽车是对象 6.关于构造函数说法错误的是() A 构造函数名与类相同 B 构造函数无返回值,可以使用void 修饰 C 构造函数在创建对象时被调用 D 在一个类中如果没有明确的给出构造函数,编译器会自动提供一个构造函数7.程序的执行结果是() public class Test { public static void main(String [] args){ String str1= new String("abc"); String str2 = new String("abc"); String str3=str1; if(str1.equals(str2)){

Java基础试题

考砸了,把做错得题目重新复习一下对应得知识点 一、单项选择(每题2、5分,20 * 2.5’=50’)A 1.下面哪种情况属于方法重载. A)方法名相同,参数类型与个数不同 B)方法参数类型相同 C)方法参数个数相同 ?D)方法名相同,方法参数类型与个数也相同 2.您想用下面得代码查找数组最后一个元素得值,当您编译并运行它得时候,会发 生什么?C public class MyAr{ public static voidmain(String argv[]){ int[]i = new int[5]; System、out、println(i[5]); } } A).编译通过并输出0 B).编译通过并输出 null C).编译通过但发生运行时错误 D).编译出错 3.JFrame得默认布局管理器就是什么?C 4.Frame得默认布局就是FlowLayout 5.JFrame得默认布局就是BorderLayout A)FlowLayout B)GridLayout C)BorderLayout D)CardLayout 6.给定下面得类定义D classBase{ Base(int i){} } class DefCon extends Base{ DefCon(int i){ //XX } } 如果将标记//XX 得地方替换为下面得行,哪一行就是独立合法得? A).super(); B).this(); C).this(99); D).s uper(99); 7.启动线程方法正确得就是___D________。 A)run()方法

B)suspend()方法 C)stop()方法 D)start()方法 6、在Java中,调用Math、random() 方法可能返回得结果就是(B) Math、random 返回得就是一个double值此值大于0、0 且小于1、0 A)132、34 B)0、342 C)29、34E10 D)1、0009 7、下面得哪一个声明就是合法得?B A) public protected amethod(int i) B)public void amethod(int i) C) public void amethod(void) D) void public amethod(int i) 8、假设有以下Java代码:C import java、applet、*; import java、awt、*; public class My_Applet extends Applet { … } 如果要在HTML页中嵌入以上Applet,可按下面()方式完成。(选择一项) A) 9、在Java中,要想使只有定义该类所在得包内得类可以访问该类,应该用(A)关键 字.? A)不需要任何关键字 B)private C)final D)protected 10、下述哪些说法就是正确得? A A)实例变量就是类得成员变量 B)实例变量就是用static关键字声明得 C)类变量在方法执行时创建 D)类变量在使用之前必须初始化 11、以下代码中哪些就是可以正确定义一个接口得。C A)abstract classAbstractTest{} B)classabstractAbstractTest{} C)interface AbstractTest{} D)class interface AbstractTest{} 12、如希望Java类中得某成员变量只能在package内部被直接访问,那么定义该

java基础测试题

1.下列哪个选项是合法的标识符 24 A.123 B._name C.class D.1first 2.下列变量定义中,正确的是1 A long 1 = 123L B long 1 = 3.14156f C int i="k" D double = 2f 3.switch语句中表达式(expression)的值不允许用的类型是124 A byte B int C Boolean D char 4.下列语句中正确的是3 A 1’ B int I=2+’2’; C string s =”on”+’one’; D byte b=257 5.下列的哪个赋值语句是不正确的 12 A.float f = ; B.double d = ; C.float d = 3.14f ; D.double f=10f; 6.下列的哪个赋值语句是正确的 2 A.char a=12; B.int a=; C.int a=12.0f; D.int a=(int); 7.给出下列的代码,哪行在编译时可能会有错误 13 ① publ ic void modify(){ ② int i, j, k; ③ i = 100;

④ while ( i > 0 ){ ⑤ j = i * 2; ⑥ (" The value of j is " + j ); ⑦ k = k + 1; ⑧ } ⑨ } A.line 4 B.line 6 C.line 7 D.line 8 8.下列关于继承的哪项叙述是正确的 3 A.在java中允许多重继承 B.在java中一个类只能实现一个接口 C.在java中一个类不能同时继承一个类和实现一个接口 D.java的单一继承使代码更可靠 9.下列哪个修饰符可以使在一个类中定义的成员变量只能被同一包中的类访问 4 A.private B.无修饰符 C.public D.protected 10.给出下列代码,如何使成员变量m 被方法fun()直接访问 3 class Test { private int m; public static void fun() { ... } } A.将private int m 改为protected int m B.将private int m 改为 public int m

相关主题
文本预览
相关文档 最新文档