Results 1 to 7 of 7
- 08-05-2012, 08:55 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 4
- Rep Power
- 0
Difference between overriding and redefining...
please see the below example ....And when we make both method static its calls accordingly the reference variable.......But still they override the method so how come the method redefining
.....i am not clear with the redefine please let explain it in more details.....
class Animal
{
void doStuff()
{
System.out.println("Aniaml");
}
}
class Dog extends Animal
{
void doStuff()
{
System.out.println("Dog");
}
}
public class TestAnimal
{
public static void main(String as[])
{
Animal a= new Animal();
Animal b= new Dog();
a.doStuff();
b.doStuff();
}
}
- 08-05-2012, 11:12 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Difference between overriding and redefining...
Make both the doStuff() methods static, ignore the warnings and run your code again. See?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-05-2012, 02:00 PM #3
Re: Difference between overriding and redefining...
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-05-2012, 02:03 PM #4
Re: Difference between overriding and redefining...
asif_plz, you didn't bother to reply to the two responses on your earlier thread.
Autoboxing & Unboxing
Not the best way to continue to get free help on a forum, that.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-05-2012, 05:36 PM #5
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Difference between overriding and redefining...
I didn't realize that an instance of a class could run the static methods of its own class. I always assumed that the only way to call a static method of class Animal is this:
Java Code:Animal.doStuff();
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-05-2012, 06:27 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Difference between overriding and redefining...
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-06-2012, 10:51 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Difference between overriding and redefining...
Please do not ask for code as refusal often offends.
Similar Threads
-
overriding
By sandeep chopparapu in forum New To JavaReplies: 4Last Post: 05-14-2012, 08:54 AM -
Overloading or Overriding...
By chathura87 in forum New To JavaReplies: 5Last Post: 02-22-2011, 01:46 AM -
overriding v/s hiding
By parminder in forum New To JavaReplies: 3Last Post: 01-17-2011, 04:24 AM -
Overriding
By prasanna1157 in forum New To JavaReplies: 7Last Post: 09-07-2010, 07:47 AM -
Overriding
By renuka_renukut in forum Advanced JavaReplies: 3Last Post: 05-21-2010, 08:45 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks