During the lab in Wednesday, we talked about inheritance. As we know, inheritance is one of the four design principles for object-oriented programs and it helps with the organization of large programs and has reusability feature. Inheritance is obtained by building new child classes from the existing parent classes. Through the magic word "extends," we can reuse and add all the methods and properties from the parent class. To reduce the chance of error and increase reusability, we can apply overriding and revise the methods in the parent class, instead of creating a new one. Inheritance represents IS-A relationship, also known as parent-child relationship.
There are five types of inheritance in Java: single, multilevel, hierarchical, multiple and hybrid. However, there are only three types of them(single, multilevel, hierarchical) available in Java programming. Not supported directly in Java, multiple and hybrid inheritance are supported through interface.
1. Single: one class inherits from the other
2. Multilevel: one class inherits from the other class which inherits from another
3. Hierarchical: multiple classes inherit from the same class
4. Multiple: one class inherits from multiple classes
5. Hybrid: a mixture of multilevel, hierarchical and multiple inheritance
The two diagrams below provide graphical representation of these types.
--------------------------------------------------------------------------------------------------------------------------There are five types of inheritance in Java: single, multilevel, hierarchical, multiple and hybrid. However, there are only three types of them(single, multilevel, hierarchical) available in Java programming. Not supported directly in Java, multiple and hybrid inheritance are supported through interface.
1. Single: one class inherits from the other
2. Multilevel: one class inherits from the other class which inherits from another
3. Hierarchical: multiple classes inherit from the same class
4. Multiple: one class inherits from multiple classes
5. Hybrid: a mixture of multilevel, hierarchical and multiple inheritance
The two diagrams below provide graphical representation of these types.
Picture References:
1.https://www.google.com/search?q=inheritance+java&biw=1280&bih=620&source=lnms&tbm=isch&sa=X&sqi=2&ved=0ahUKEwiZ7-WRjp3QAhXB5yYKHT0JBssQ_AUIBygC#imgrc=NTtuIobiMKjsUM%3AWriting
2. http://www.javatpoint.com/inheritance-in-java
References:
1.http://www.javatpoint.com/inheritance-in-java
2.https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
3.http://docstore.mik.ua/orelly/java-ent/jnut/ch03_04.htm
--------------------------------------------------------------------------------------------------------------------------


Inheritance was for sure interesting although a bit complicated. But I see how we can simplify a program that would be super messy if we just coded the whole thing in one main function. I would imagine that the multilevel version of inheritance is probably very complex as names would start to get super confusing because your calling so many functions. Would you say inheritance is the best way to code or is their an even better method to further simplify code?
ReplyDeletecool article! I think the reusability aspect of inheritance is what makes it the most interesting. It seems like it really cuts out a lot of unnessesary programming. I didnt know there were multiple levels to inheritance, do you know what someone might use multilevel or heirarchical inheritance for?
ReplyDeleteThis is an interesting article! It was cool to learn about all the different ways that inheritance can be used, as it extends so much beyond just single and multi-level structures. I think the "Multiple" structure is particularly fascinating. What are some sub-classes that are able to inherit from multiple classes?
ReplyDeleteI just finish the lab for our section and find that This is a really helpful journal!I didn't know about there are so many different types of inheritances. And I think the one that we just did in class is a Hierarchical. Inheritance can really help us reduce a lot of unnecessary codes that we have to put into subclasses.
ReplyDeleteGreat article !especially since we have been talking about inheritance for the last couple of days in class so it's nice to combine everything with what we've learned and i'm pretty sure that the different kinds of inheritance are very useful for different task.I wonder what would be these tasks ?
ReplyDeleteNice article. I think its cool that inheritance can have so many levels. Especially hybird inheritance that can have a mixture of the other kinds of inheritance. To think of objects that might have that many different sub classes is pretty cool to me, because when looking at programming assignment 10 it has alot of subtypes, but to think there could be even more is cool to me
ReplyDelete