• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

About Main Class

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello !!!
Since I am a beginner in Java programming I do not use an IDE. I am using notepad++ to write my Java codes. But an expert in java will find this question ridiculous.
I created a super class in package x and a subclass was derived from the super class, but that subclass is in a different package (Lets assume it is package y).
Then I built my main/test class in another package (package z). When I compile my main class the compiler says Error :class,interface or enum expected.
Does what I have done make any sense ?
I know sub classes and super classes do not need to be in the same package. But what about the test class. Should it be the same package where I created my super class/sub class.

 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That error message is often associated with putting code outside of a class that should be inside a class but without seeing your code you are unlikely to get a more definite answer.

 
Gihan Madushanka
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:That error message is often associated with putting code outside of a class that should be inside a class but without seeing your code you are unlikely to get a more definite answer.



 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don’t use the code button, so everybody can see how your code is indented, how can we see whether your {} are paired correctly?
 
Gihan Madushanka
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:If you don’t use the code button, so everybody can see how your code is indented, how can we see whether your {} are paired correctly?


Sorry !
Corrected it
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here class tea is only available for package y because it has no public access specifier and it is defaulted to its package(package y) it cannot be used in other packages
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to go back to the tutorial since your use of the 'package' statement is heavily flawed for all your classes. Also, start with something simple.
 
Campbell Ritchie
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure you ought not to have a { after the package name and before the class name.
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic