| Author |
beginning of Inheritance and the error
|
kazi Shahin
Greenhorn
Joined: Nov 14, 2010
Posts: 20
|
|
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.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
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
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
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
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
kazi Shahin
Greenhorn
Joined: Nov 14, 2010
Posts: 20
|
|
The public type inheritenceTry0 must be defined in its own file
Actually what does this error means?
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
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
Joined: Nov 14, 2010
Posts: 20
|
|
I'm tring and tried.
what does it mean "in its own file " ?
What is it own file?
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
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
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5888
|
|
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
Joined: Nov 14, 2010
Posts: 20
|
|
Still a bit confused.
I think, there are error in class declaration.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
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
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4167
|
|
|
kazi, how do you write your code?
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5888
|
|
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
Joined: Nov 14, 2010
Posts: 20
|
|
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?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Nov 14, 2010
Posts: 20
|
|
|
I want to clear how to pile all class with the main class?
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4761
|
|
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
Joined: Jan 03, 2004
Posts: 5888
|
|
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.
|
 |
 |
|
|
subject: beginning of Inheritance and the error
|
|
|