This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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

Win a copy of Head First Android this week in the Android forum!
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="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
I agree. Here's the link:
subject: compile time errors
jQuery in Action, 3rd edition