• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Using sublime to code Java class. How to import another class file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

New to Java.

I have written a class named School with few attributes and 2 simple methods. This java file compiled successfully.

I want to instantiate object of this School in another class called SchoolApp which has Main method. I am using sublime as text editor.

How to import or refer the School class file in my SchoolApp file?

Here is the code of SchoolApp file:



When I compile SchoolApp (javac SchoolApp.java), I am getting the following error:

SchoolApp.java: error: cannot find symbol
School aschool = new School();

I am sure I don't know how to reference School class in my SchoolApp.java file. Any suggestions how to fix this.

Thank you very much
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jasonsmith nath wrote:I have written a class named School with few attributes and 2 simple methods. This java file compiled successfully.



And what package is it in? If you put it in the School package then you shouldn't have to import it into SchoolApp, so it appears you didn't put it there. If you didn't put it into any package then you won't be able to import it into SchoolApp, so if that's what you did then you're going to have to put it into some package.

To me it seems like it ought to be in the School package too, so why don't you try putting it there? No import would be necessary then.

Also... it's standard for package names to start with lower-case letters, e.g. "school". Right now your "School" package can be confused with your "School" class by people reading your code.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic