380 likes | 1.29k Views
Inheritance in Java is one of the primary keys to unlocking the object-oriented programming approach to design software. This tutorial here will help you learn the fundamentals of Inheritance in Java through some exciting real-time examples <br><br>About Simplilearn Java certification training course:<br>If youu2019re looking to master web application development for virtually any computing platform, this Java Certification Training course is for you. This all-in-one Java training will give you a firm foundation in Java, the most commonly used programming language in software development.<br><br><br>This advanced Java Certification Training course is designed to guide you through the concepts of Java from introductory techniques to advanced programming skills. The course will provide you with the knowledge of Core Java 8, operators, arrays, loops, methods, and constructors while giving you hands-on experience in JDBC and JUnit framework.<br><br><br>Java Certification Course Key Features:<br>1. 70 hours of blended training<br>2. Hands-on coding and implementation of two web-based projects<br>3. Includes Hibernate and Spring frameworks<br>4. 35 coding-related exercises on Core Java 8<br>5. Lifetime access to self-paced learning<br>6. Flexibility to choose classes<br><br><br>Eligibility:<br>Simplilearnu2019s Java Certification Training course is ideal for software developers, web designers, programming enthusiasts, engineering graduates, and students or professionals who wish to become Java developers.<br><br><br>Pre-requisites:<br>Prior knowledge of Core Java is a prerequisite to taking this advanced Java Certification training course. Our Core Java online self-paced course is available for free to become familiar with the basics of Java programming.<br><br><br>uf449Learn more at: https://bit.ly/3b6SCvp<br>
E N D
Agenda Why do we need inheritance? What is Inheritance? Components of Inheritance Diamond Problem Extend Keyword IS-A Relation Access Modifiers HAS-A Relation Super Keyword Types of Inheritance
What is Inheritance? Inheritance is an act through which a new class gets created by acquiring the variables and methods defined in the previous(parent class).
What is Inheritance? Food() Fruits() Veggies() Noodles()
Why do we need Inheritance? We implement Inheritance for multiple reasons. Like: Creating a possibility to add or remove features. To reduce the code length as we reuse the code. More comfortable to develop and maintain the Project.
Why do we need Inheritance? Call() SMS()
Why do we need Inheritance? Media() Call() SMS() Browse()
Why do we need Inheritance? Call() SMS() Media() Call() SMS() Browse()
Why do we need Inheritance? Call() SMS() Inherit Media() Browse()
Components of Inheritance Inheritance has two major components, those are mentioned as follows: Parent class/Super class Child class/Sub class Parent Class Child Class
Extends Keyword The term “extends” is a predefined keyword in java, that allows you to create a new child class by deriving the variables and methods from the parent class to reduce code length and improve the performance.
Access Modifiers Access Modifiers Private Public Protected Default
Access Modifiers Default Default Access Modifier is set implicitly whenever you declare a class without a specific access modifier. By default, the access of a class or method, when declared without a specific access modifier, becomes available to any other method or class within the same package,
Access Modifiers Public A certain class can be declared as Public by using the keyword “public.” Any class or method when declared as public, becomes available to any class or method declared in the same package, but if a different method or class needs it, it should be imported
Access Modifiers Protected A certain class is declared protected by using the keyword “protected.” This provides access to methods and variables of the protected class only to the rightful subclasses and protects the data from any other classes which are not related.
Access Modifiers Private A certain class is declared protected by using the keyword “private.” This provides the ultimate protection to the data members and the methods of the private class. This procedure is implemented by class to encapsulate the methods and members.
Super Keyword Super Keyword eliminates the confusion between parent class method and subclass method. Super keyword is implemented to access a method or constructor that is defined in the parent class
Types of Inheritance A A A A B B B C D B C C D Hierarchal Inheritance Hybrid Inheritance Single Inheritance Multi-Level Inheritance
Types of Inheritance A Single Inheritance consists of one parent class and one child class. Here, child class inherits parent class methods and data members. B Single Inheritance
Types of Inheritance A Multi-Level inheritance is also a parent child inheritance relation but the difference is the child class is inherited by another child class. B C Multi-Level Inheritance
Types of Inheritance A Hierarchical Inheritance is a parent child relationship. The only difference is, here, multiple child classes inherit one parent class. B C D Hierarchical Inheritance
Types of Inheritance A The name itself explains us all. The Hybrid Inheritance can be a combination of any of the three types of inheritances supported in Java. B C D Hybrid Inheritance
Diamond Problem A Java programming Language does not support Multiple Inheritance as it ends up with a serious ambiguity. B C D Diamond Problem
IS-A Relation Fruit IS-A When a class inherits methods and members from a different class, then the relation is said to be an IS-A Relation. Example: Orange IS-A Fruit. HAS-A Orange Citrus Taste
HAS-A Relation Fruit IS-A When a class inherits an instance from a different class or an instance or its own class, then the relation is a HAS-A type. Example: Orange HAS-A Citrus Taste. HAS-A Orange Citrus Taste