| Author |
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[]) { printYourself(); } 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 thanks venkat
|
 |
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>
|
 |
 |
|
|
subject: compile time errors
|
|
|