wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classes" Watch "classes" New topic
Author

classes

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
the following code compiles without problems:
package points;
class Point {
int x, y;
PointList list;
Point next;
}
class PointList {
Point first;
}
--------------------------------------------------
why this one has problems to compile???
package points;
public class Point {
int x, y;
PointList list;
Point next;
}
public class PointList {
Point first;
}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What errors do you get when you compile the 2nd one?


GenRocket - Experts at Building Test Data
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I guess he's got problems because of two public classes in one file.
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Jbuilder 6 enterprise:::::
"Caller.java": Error #: 475 : class Point is public; must be declared in a file named Point.java at line 10, column 8
"Caller.java": Error #: 475 : class PointList is public; must be declared in a file named PointList.java at line 12, column 8
Obs::::
I have one file with both classes!!
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
yes but in the first case (without keyword public)
it compiles!!! why???
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Originally posted by leandro oliveira:
Another problem (Every thing is in one single file named Caller.java)

JBuilder says:"Caller.java": Error #: 303 : 'this' cannot be referenced from a static context at line 4, column 10
the following works:

this do not work:

Conclusion:
which modifier is correct to use with classes A and B??? why am I having problems with the first code???
[ edited to surround code with the [code] and [/code] UBB Tags -ds ]
[ December 23, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I have one file with both classes!!
but in the first case (without keyword public) it compiles!!! why???

Because you are allowed to have more than one class definition in a single source file. You aren't allowed to have more than one public class definition in a single source file, and the name of any public class must match the name of file (so, a public class Foo must be defined in a file named Foo.java and Foo.java must not include any other public class definitions).
Them's the rules and keeping the rules simple like this allows the Java compiler to function without the use of a makefile that would provide further instruction to the compiler as to what it's supposed to do with some source file(s) and any class(es) defined inside. Somebody else with more experience using makefiles in other languages might mosey on by to provide a better explanation of what's going on.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
GeeCON Prague 2014
 
subject: classes