
The reference type determines the data you access in an inheritance tree. This lecture demonstrates this in action and also the fact that you can cast the reference to access data from different parts of the tree.
Some core concepts in this lecture! A diagram is used to explain method overriding, polymorphism and data hiding. Understanding the difference between the reference and the object is crucial here also. For polymorphic (instance) methods, refer to the object type; for data and static methods, refer to the reference type.
Covariant returns is presented in this lecture. A polymorphic method call is executed where the return type is a subtype of the parent method.
This lecture emphasises the fact that the reference type determines the methods you can call. Diagrams are used to explain the hierarchy and the in-memory representation of the reference and object types. Downcasting, which requires a cast is also discussed (and why it does not generate a ClassCastException).
This lecture discusses various Java 8 interface methods to see which will compile and which will not.
Have ambiguous fields in itself is not an issue but referring to them is when you get the problems.
The getClass() method returns the class name of the object that the reference is referring to. This question demonstrates this by having a List reference refer to an ArrayList object - the getClass() returns java.util.ArrayList.
Using diagrams, this lecture demonstrates that the reference type determines the data accessed, regardless of whether the data is static or instance data.
This lecture demonstrates that final classes cannot be extended. Note also that final methods cannot be overridden.
Given a textual description of a design problem, would you override or overload? The answer is to override but in the answer, overloading is compared.
Using both diagrams and code this lecture shows that you have to be careful accessing data higher up the inheritance tree. For example, you cannot access the data if it is marked private.
Whether you use the keywords or not, interface fields are implicitly public, static and final. This lecture demonstrates that.
Interface methods are abstract and since Java 8, you can have default and static interface methods with implementation code. This question tests that knowledge.
This question presents a hierarchy which I diagram. We are asked which of the following reference assignments will not compile. This leads to a discussion where I explain how you end up with ClassCastExceptions.
This lecture demonstrates that while one interface is extending another we can (in the sub-interface):
re-define a parent default method and make it abstract
re-define a parent default method and provide a different implementation
Non-static methods cannot be overridden by static methods and vice versa. Static methods are never overridden, they are hidden. A methods signature consists of the method name and the order and type of its parameters/arguments. For instance/static data use the reference type; for instance (i.e. polymorphic) methods use the object type.
Interfaces can extend from other interfaces. A sub-interface can include a method signature that matches a parent interfaces method without causing ambiguity.
A reference to a static field causes initialization of only the class or interface that actually declares it, even though it might be referred to through the name of a subclass, a subinterface, or a class that implements an interface.
Given an interface, we are asked which of the following code segments are valid. The ones that are correct are: the interface that extends the interface given; and the abstract class that implements the interface given, even though it does not implement any of the given interfaces methods.
This is the lecture that deals with overriding a method which has exceptions in it method signature. Both diagrams and code are used to explain this important concept.
Sample reviews:
"Absolutely fantastic!" - Mitchell M.
"This is an excellent resource for OCA preparation. Thanks indeed." - Shankar M.
"Another excellent course by Dr. Sean Kennedy. This course, combined with the Java 8 OCA course offered by Dr. Kennedy, are a must if you are looking to get your OCA certification." - William M.
"Brilliant breakdown of concepts, BRILLIANT!!" - Nhlanhla S.
"This is a fantastic practical test with explanations , which explain the most important concept in Java OOP - Inheritance . What are you waiting for, catch it? And be an excellent prepared with all thricky hints for your Progress Review at work , school or University. I absolutely rated with 5 Stars." - Valentin G.
"Instructor explained the topic of Inheritance succinctly. It's a good match for me as its a short course which I was able to complete the course on time. And also because there were quizzes covered on important topics. Thank you very much for the lovely course once again Sir. Cheers!" [Venkataramana N.]
"Amazing course & explanations..." - Kiran N.
"Very good, simple, targeted explanations without any extraneous discussion and filler. I highly recommend." - Kevin H.
"Nice and clear explanations!" - Ali A.
"Good job Sir !" - Smail A.
"explanation is amazing, presentation is good to understand." - Yan S.
This is one category (of eleven) from my systematic preparation course for the 1Z0-808 Oracle Java SE 8 Programmer 1 (OCA) exam which I have delivered several times; both in person and online.
This Inheritance course is not a notes-based course. As the Oracle exam is based on multiple choice questions (MCQ), this course focuses completely on MCQ using the excellent Enthuware tool. In fact, Enthuware supplement their explanations by referring to my online explanations.
In this course, I answer 20 random questions from Enthuware's Inheritance category and use diagrams and code where needed. The diagrams in particular are extremely helpful when explaining Inheritance-related concepts. For example, a UML diagram helps greatly with explaining why a reference of type Car cannot refer to an object of type Vehicle. The other type of diagram I use frequently is the in-memory representation of references referring to objects. Separating these two concepts (references and objects) is critical to answering many MCQ-style questions.
While the course is ideal for those preparing for the 1Z0-808 exam, the topics discussed will benefit anyone trying to understand Inheritance at a deeper level. For example, the following topics are all covered:
method overriding
polymorphism
covariant returns
where the parent method throws exceptions
method overloading
upcasting and downcasting
shadowing - both methods and data
the reference type determines the methods accessible
the default modifiers applied to interface data
the types of methods allowed in interfaces
why an abstract class can implement an interface without implementing any of the interfaces' methods
ClassCastExceptions