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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help" Watch "Help" New topic
Author

Help

James Sinarit
Greenhorn

Joined: Mar 13, 2005
Posts: 1
I need help:
here is the code:

public class Integer {

public int i = 1;

public static void main(String args[]) {

}
}

class other {
public static void main(String args[]) {
System.out.println( i );
}
}

How can I make it display the variable i in the other class?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi James,

Welcome to JavaRanch!

"i" is a member variable in your Integer class. One copy will exist inside each Integer object you create. Your main method has to create an Integer, and then access its "i" member:

Integer anInteger = new Integer();
System.out.println(anInteger.i);

Note that "Integer" is the name of one of the core Java classes, and as such should be avoided as a name for your own classes!


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help
 
Similar Threads
JAVAC not found ??? I cant compile - help
can't run
passing message between two programs(.java files)
try again
Inner class and this ?