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

beginning of Inheritance and the error

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have code


















This showing the following error


Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The public type inheritenceTry0 must be defined in its own file
The public type inheritenceTry1 must be defined in its own file
The public type inheritenceTry2 must be defined in its own file

at inheritenceTry1.<init>(inheritenceTry.java:22)
at inheritenceTry.main(inheritenceTry.java:7)


How can I solve it.

I have just tried to practice inheritance code.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:
This showing the following error


Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The public type inheritenceTry0 must be defined in its own file
The public type inheritenceTry1 must be defined in its own file
The public type inheritenceTry2 must be defined in its own file

at inheritenceTry1.<init>(inheritenceTry.java:22)
at inheritenceTry.main(inheritenceTry.java:7)


How can I solve it.

I have just tried to practice inheritance code.




It is generally a good idea to give us the error message from the compiler -- instead of the error messages from the IDE that is trying to run code that hasn't been completely compiled. In fact, I will go one step further, and say that it is never a good idea to run code that didn't compile correctly.

Henry
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:How can I solve it.


Well, the first thing is to read the message.

What do you think
"The public type inheritenceTry0 must be defined in its own file"
might mean?

(Hint: where is inheritenceTry0 defined?)

Winston
 
kazi Shahin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The public type inheritenceTry0 must be defined in its own file

Actually what does this error means?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:The public type inheritenceTry0 must be defined in its own file
Actually what does this error means?


It means exactly what it says: the class inheritenceTry0 must be defined in its own file.

I ask again: which file is it defined in right now?

Winston
 
kazi Shahin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm tring and tried.

what does it mean "in its own file " ?

What is it own file?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:I'm tring and tried.


Tough. We don't simply hand out answers here; you have to work a bit too.

what does it mean "in its own file " ?
What is it own file?


I will ask for the last time: What file is inheritenceTry0 defined in?

Now:
1. Why do you think that might NOT be the right file?
2. Why aren't you getting the error message for inheritenceTry?

Winston
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:I'm tring and tried.

what does it mean "in its own file " ?

What is it own file?



It means not in a file with some other public class. "Its own" means "belonging to that class, and separate from those of other classes."

For instance, a child might say, "I want my own room," meaning he doesn't want to share a bedroom with his brother.
 
kazi Shahin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still a bit confused.
I think, there are error in class declaration.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:Still a bit confused.
I think, there are error in class declaration.


Well that's a given, since you're getting errors. Have you answered my questions?

If you have, and you still can't work out what the problem is, then I suspect you need to read the tutorials.

Winston
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kazi, how do you write your code?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:Still a bit confused.



About what?

Do you know what a class is?

Do you know what a file is?

Do you understand the difference between a class being in a file all by itself, and being in a file with other classes?
 
kazi Shahin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Yes, .java is the file and a file contains a class. in every file there may be lots class but must have a main class.
At the beginning of my post, I have code several class but, don't know clearly how to pile all class together.


But, I I'm not clear about

Jeff Verdegan wrote:

kazi Shahin wrote:Still a bit confused.



Do you understand the difference between a class being in a file all by itself, and being in a file with other classes?

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:
in every file there may be lots class


hmm, there might be many player for a team. but only captain have rights to take outside world. it is your choice to make a captain among others(classes)

<edit>corrected typo</edit>
 
kazi Shahin
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to clear how to pile all class with the main class?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote: I want to clear how to pile all class with the main class?


1. Put them in a package.
2. Make them something other than public.
3. Read the tutorial link I gave you above.

I recommend #3.

Winston
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kazi Shahin wrote:in every file there may be lots class



Yes, but there shouldn't be. In most cases, you should define only one class per file, or at least only one top-level class. And only one top-level class can be public.

but must have a main class.



No, but to invoke the JVM, you must provide it a class with a main() method.

At the beginning of my post, I have code several class but, don't know clearly how to pile all class together.



The usual way is to put each class into a file, and the compile all those files. If it's more than a trivial program being done as an educational exercise, you'll probably have a package structure, and you'll probably bundle them all into a .jar file to deploy it.

 
reply
    Bookmark Topic Watch Topic
  • New Topic