File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Method Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method Problem" Watch "Method Problem" New topic

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(){
void g(){
System.out.println(a+" "+ " "+b+" "+ " "+c );


public static void main(String args[]){

palindrome p=new palindrome();


Please clarify my doubt friends
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15100

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 8 API documentation
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11957

What would you expect to happen if your main looked like this:

What, exactly, would the p in the j() method refer to?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Method Problem
jQuery in Action, 3rd edition