The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compile time errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compile time errors" Watch "compile time errors" New topic

compile time errors

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
class Animal
public void eat()
public void printYourself()
System.out.println("in animal");
public class Horse767 extends Animal
public static void main(String args[])
public void printYourself()
super.printYourself(); // Invoke the superclass

hi all,
the above program is giving compile time errors.can anybody provide the explanation for the above as why its giving compile time errors

Ashok Kumar
Ranch Hand

Joined: Aug 27, 2004
Posts: 93
The error reads as follows:

non-static method printYourself() cannot be referenced from a static context

Which is self explanatory

"Decide what you want, decide what you are willing to exchange for it. Establish your priorities and go to work."
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
main() method is a static method method. we can't acess non static methods and non static variables within static methods. so compiler shows the error message. Just change your code like new Animal().printYourself().

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
I agree. Here's the link: http://aspose.com/file-tools
subject: compile time errors
Similar Threads
Inner class compile time errors
Overriden Method
Multiple super statements
about arrays
Confused with instanceof, please help