Topic: 那里错了

  Print this page

1.那里错了 Copy to clipboard
Posted by: xiaopan
Posted on: 2003-03-17 13:25

1. package foo;
2.
3. import java.util.Vector;
4.
5.private class MyVector extends Vector{
6. int i=1;
7. public MyVector(){

8. i = 2;
9. }
  
10.}
11.
12. public class MyNewVector extends MyVector{
13. public MyNewVector(){

14. i=4;
15. }
16. public static void main(String args[]){
17. MyVector v= new MyNewVector();

18. }
19. }

what is the result?
a.Compilation succeeds.
b.Compilation fails because of an error at line4.
c.Compilation fails because of an error at line6.
d.Compilation fails because of an error at line14.
e.Compilation fails because of an error at line17.

为什么错在17行,我在编译时告诉我5行不能声明为PRIVATE ?请高手指教

2.Re:那里错了 [Re: xiaopan] Copy to clipboard
Posted by: kenwil
Posted on: 2003-03-17 14:30

you should use public on line 5 so can make a class, method, or variable accessible from any other class

3.Re:那里错了 [Re: xiaopan] Copy to clipboard
Posted by: xiaopan
Posted on: 2003-03-17 15:19

I know that the wrong line is 5 but what the key is e

4.Re:那里错了 [Re: xiaopan] Copy to clipboard
Posted by: yj780210
Posted on: 2003-03-18 09:04

从外部访问不到MyVector 当然出错了。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923