File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Problem

 
Ganesh Kumar
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you expect to happen if your main looked like this:



What, exactly, would the p in the j() method refer to?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic