Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Asking you the two problems:  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!