Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

constructor basic question

Status
Not open for further replies.

786snow

Programmer
Nov 12, 2006
75
0
0
Code:
public class HelloWorldApp1 {
  
   
	//delaring constructor
	public HelloWorldApp1()
	{
		 int grade1=7;
		 


	}
....


Hi, if I have a constructor in my programe now how can I access the value of grade1.
When in my method if I do System.out.print(grade1); i get error
 
could you do it like this

public class HelloWorldApp1 {

private int grade1;

//delaring constructor
public HelloWorldApp1()
{
grade1=7;



}

public void printstuff() {
System.out.print(grade1);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top