• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Marshal
Posts: 25950
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
It's a tiny ad. At least, that's what she said.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic