aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static methods" Watch "static methods" New topic
Author

static methods

arivarasan manivasagam
Greenhorn

Joined: Oct 17, 2005
Posts: 2
import java.io.*;
public class Mine {
public static void main(String argv[]){
Mine m=new Mine();
System.out.println(m.amethod());
}
public int amethod() {
try {
FileInputStream dis=new FileInputStream("Hello.txt");
}catch (FileNotFoundException fne) {
System.out.println("No such file found");
return -1;
}catch(IOException ioe) {
} finally{
System.out.println("Doing finally");
}

return 0;
}

}

the above code compiles fine.
how are we able to access the nonstatic method(amethod) from our static main method?
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580

System.out.println(m.amethod());


call to method is using object m, so it is possible
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580

System.out.println(m.amethod());


call to method is using object m, so it is possible


System.out.println(amethod());


call to method is using withou object so it is not possible
Ramya Iyer
Ranch Hand

Joined: Jul 29, 2003
Posts: 66
Please place code within the "" tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static methods