• Post Reply Bookmark Topic Watch Topic
  • New Topic

About Main Class  RSS feed

 
Gihan Madushanka
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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.

 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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.



 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
bala nannaka
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure you ought not to have a { after the package name and before the class name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!