Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classes

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What errors do you get when you compile the 2nd one?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess he's got problems because of two public classes in one file.
-Barry
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes but in the first case (without keyword public)
it compiles!!! why???
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic