| Author |
Method Problem
|
Ganesh Kumar
Ranch Hand
Joined: Jul 02, 2007
Posts: 113
|
|
Hi friends , Why cant we access a method from another method using the instance as shown below class palindrome{ static int a,b,c; void j(){ System.out.println("hi"); p.g(); } void g(){ a=10; b=20; c=40; System.out.println(a+" "+ " "+b+" "+ " "+c ); } public static void main(String args[]){ palindrome p=new palindrome(); p.j(); } } Please clarify my doubt friends
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
The variable 'p' is a local variable in the main() method. It isn't visible in method j(). See: The Java Tutorial - Variables. Note: Please use code tags when you post code, that will make your code easier to read in the forums.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9948
|
|
What would you expect to happen if your main looked like this: What, exactly, would the p in the j() method refer to?
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: Method Problem
|
|
|