Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Hi All,
We cannot override static methods to non-static and non-static methods to static. Compilation fails if we try to do so. Then what is redefining?
Can anyone please explain with an example?
Thanks,
- Surya.
~ Pratibha Malhotra<br /> <br />Sun Certified Java Programmer<br />SCEA 1.4 (In Progress)<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />"Many of life's failures are people who did not realize how close they were to success when they gave up!!"
Anything acquired without effort, and without cost is generally unappreciated, often discredited<br />-:Napoleon Hill
Originally posted by Sai Surya:
Here is the code which I got from K&B book which is compiling fine.
<CODE>
class Animal {
static void doStuff() {
}
}
class Dog extends Animal {
void dostuff() {
}
public static void main(String [] args) {
}
}
</CODE>
Here is my code which I wrote, NOT getting compilied.
<CODE>
class Parent {
static void aMethod() {
}
}
class OverrideTest extends Parent {
void aMethod() {
}
public static void main(String[] args) {
}
}
</CODE>
I am not able to find out the difference.
- Surya.
Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Java Coach - Scrum Master - Enterprise Integration Specialist
Originally posted by Dylan Honorez:
That example is showing
static void aMethod()
void aMethod()
and compilation fails because you changed a static method to a non-static method.
SCJP 5
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Java Coach - Scrum Master - Enterprise Integration Specialist
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Originally posted by Jothi Shankar Kumar Sankararaj:
Hi Dylan,
Thanks for summing it all up. So static methods can't be overriden nor be overloaded. Anyone for corrections on this?
Regards,
Jothi Shankar Kumar. S
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Anything acquired without effort, and without cost is generally unappreciated, often discredited<br />-:Napoleon Hill
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Originally posted by Jothi Shankar Kumar Sankararaj:
Thanks for all your reply. But with respect to the above code what will the compiler do? Which method will it call and why?
Regards,
Jothi Shankar Kumar. S
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Fire me boy! Cool, soothing, shameless self promotion:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|