• 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

Vector cannot be private?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I`m developing at the moment this class ( a graph containg nodes and edges etc.)

Why is it not possible to declare the global variables as private?

Graph.java:3: modifier private not allowed here


thx for answers
Robert Ploch
[ May 19, 2003: Message edited by: Robert Ploch ]
[ May 19, 2003: Message edited by: Robert Ploch ]
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why you see that error, but you have to fully qualify Vector or import it. Otherwise, you will see an error complaining about not understanding vector. Use:
import java.util.Vector;
on the top line and see if that helps.
Other points, they're member variables, not globals. Java does not permit global variables. Member variables can, of course, be private. There's nothing illegal in how you've declared them. However, member variables should start with a lower-case letter. Code is communication. By following conventions you communicate effectively!
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the explanation of global variables. I screwed some definitions
I tested your hint, but the compiler (newest version) still posts this error. It doesn`t depend only on the Vector-Class, the compiler is already complaining about the int with the same error.
It also confuses me, because i didn`t do it different than all the times before.
But see yourself
You`ll find the files on:
www.robertploch.de/files/Node.java
www.robertploch.de/files/Edge.java
www.robertploch.de/files/Graph.java
[ May 19, 2003: Message edited by: Robert Ploch ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If Nodes and Edges are class names then you cannot also use them as variable names.
To avoid this be sure to follow the Java naming conventions of using lowercase for the initial letter of variable names, and uppercase for classes.
hth,
bear
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, but the variables do have the name`s: Edges & Nodes;
the class`s names are Edge & Node, without 's', so it should`nt come to an error ( i hope )
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is absolutley nothing wrong with using private where you are using it. What version of Java? Using an IDE? Can you compile a program that has nothing except a single private variable?
 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think i`ve got the error
i programmed another, still unready file in the same directory as Graph.java
javac compiled everything and only showed some errors in the unready file.
now i`ve deleted the file and some errors in graph.java were born
ok, now bugfixing
thx for helping
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, but the variables do have the name`s: Edges & Nodes; the class`s names are Edge & Node, without 's', so it should`nt come to an error
I strongly recommend that you follow Java Coding Conventions, -- it will make it easier for everyone (including you) to understand your code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic