Results 1 to 6 of 6
Thread: Overiding an abstract method
- 01-02-2008, 06:46 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 49
- Rep Power
- 0
Overiding an abstract method
I tried to override an abstract method in a child class but complier complains and does not allow me to do this. Is it a rule or I am making some mistake?
- PEACEJava Code:public class Jupiter { public static void extractUsers() { } } public class Moon extends Jupiter { public void extractUsers() { } }
- 01-02-2008, 06:59 PM #2
Your code didn't compile for me either, but the following did:
You can't override a static method as you did above, but the above code I posted does work. I'm not sure about your abstract method because I don't see one.Java Code:public class Jupiter { public static void extractUsers() { System.out.println("Superclass output"); } } public class Moon extends Jupiter { public [B]static [/B]void extractUsers() { System.out.println("Subclass output"); } }
EDIT: see here for great info on the matter.Last edited by CaptainMorgan; 01-02-2008 at 07:11 PM.
- 01-02-2008, 07:43 PM #3
Abstract method
Hello, eva.
An abstract method can only be declared in an abstract class. Also, when you "override" an abstract method it is actually called implementing that method. Remember that an abstract method cannot do anything by itself.
Java Code:public [COLOR="RoyalBlue"]abstract[/COLOR] class Jupiter { public [COLOR="RoyalBlue"]abstract[/COLOR] void extractUsers() { System.out.println("Superclass output"); } }Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-02-2008, 07:48 PM #4
- 01-03-2008, 09:30 AM #5
Member
- Join Date
- Dec 2007
- Posts
- 49
- Rep Power
- 0
Hi everyone,
Thanks for the explanation. I now realize that my code was horribly wrong. I learned a lot of things though.
Chao.
- 01-03-2008, 04:29 PM #6
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
Can this be done using abstract class??
By romina in forum New To JavaReplies: 6Last Post: 03-02-2009, 12:46 PM -
Error! "filename" is not abstract and does not override abstract method...
By hasani6leap in forum New To JavaReplies: 6Last Post: 10-27-2008, 12:25 AM -
Abstract Class
By gapper in forum New To JavaReplies: 4Last Post: 01-31-2008, 01:25 PM -
GUI for Abstract...
By judepereira in forum AWT / SwingReplies: 0Last Post: 01-04-2008, 08:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks