| Author |
Asking you the two problems:
|
Tu Ran
Ranch Hand
Joined: Feb 09, 2002
Posts: 30
|
|
package Base; class Base{ protected void amethod(){ System.out.println("amethod"); }} class Class1 extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); } }//Why it can compile but throw a "NoClassDefFoundErro" second: In the SCJP examination,whether it should need us to different from reserved words and key words or not : if it demanded,please tell me what are the keywords,and what are reserved words in SCJP examination? Thanks a lot~~ [ February 23, 2002: Message edited by: Tu Ran ]
|
Enjoy java,enjoy life
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
1. What is the stack trace exactly? What is command line you use to run the program? Sounds like a classpath problem to me... Try going into the directory Base and type: java -classpath . Base.Class1 or if you are in directory Base you can type java -classpath .. Base.Class1 let me know 2. Keywords have been heavily discussed in the following threads: http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014367 http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014586 [ February 23, 2002: Message edited by: Valentin Crettaz ]
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Holmes Wong
Ranch Hand
Joined: Feb 18, 2002
Posts: 163
|
|
I ran your code, and no problem with it. The problem is probably with your class path. Did you run your code inside package or outside it?
|
 |
Jian Yi
Ranch Hand
Joined: Feb 01, 2002
Posts: 127
|
|
Hi Valentin & Holmes, Do I have to create Base directory and move the .class files to Base dir by my own? Is there a way to get it done automatically? Since javac doesn't create Base dir for you even though we specify the package as Base in our java file. Thanks, Jenny
|
 |
Holmes Wong
Ranch Hand
Joined: Feb 18, 2002
Posts: 163
|
|
I think you cannot automatically generate a package specified by you from my understanding. What if you have many files in one package? You must move all these files inside this package if packane name for these files are specified on the first line of your code. Unless you do not specify, then you will have a default package that is your current directory.
Originally posted by Jenny Yin: Hi Valentin & Holmes, Do I have to create Base directory and move the .class files to Base dir by my own? Is there a way to get it done automatically? Since javac doesn't create Base dir for you even though we specify the package as Base in our java file. Thanks, Jenny
|
 |
 |
|
|
subject: Asking you the two problems:
|
|
|