I am currently revising for a Java se7 certification and anyone who has done any of these exams knows how ridiculous some of the code samples they use are. Purposely writing code that is awkward to understand. Recently I have seen alot of code written like this:
Object obj=new Animal();
What benefit does this provide? I understand this is valid code, however is this just one of those things that you would just never use like alot of the code in the exams? If not when and why would you do this?
It demonstrates that Object is a base class (parent class) of Animal.
In other words, even though you didn't write
public class Animal extends Object {
}
The compiler added in the "extends Object"; because, all classes extend Object.
This is true for all classes in the Java language, and while the example is poorly chosen for the purposes of teaching, it is (in some ways) a so-so way of testing if you understand such a concept. Odds are you will not use this technique in regular development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With