This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help" Watch "Help" New topic


James Sinarit

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

Joined: Jul 08, 2003
Posts: 24195

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();

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:
subject: Help
jQuery in Action, 3rd edition