More on inheritance

Let's discuss some notorious tricky questions and misconceptions regarding inheritance in Java. 

Let's get started with some of the more well-known questions asked concerning inheritance. Take a look at the following block of code:

class X{    //Class X members}class Y{    //Class Y members}class Z extends X, Y{    //Class Z members}

In the preceding code snippet, we have the X and Y class and some data fields or methods inside it. The Z class inherits the X and Y classes. Is this allowed? The answer is no. Java does not allows multiple inheritances, whereas it is allowed in C++. So here, we can conclude that the preceding code snippet is not right and will throw an error.

This is also one of the differences between inheritance ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.