Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.

Slides:



Advertisements
Similar presentations
1 Inheritance Classes and Subclasses Or Extending a Class.
Advertisements

Object Oriented Programming
Chapter 1 Inheritance University Of Ha’il.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis 1.
©NIIT Inheritance and Interfaces Lesson 1A / Slide 1 of 23 Programming in Java Objectives In this lesson, you will learn to: Implement the concept of inheritance.
Advanced Programming in Java
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Huron High School AP Computer Science Instructor: Kevin Behmer S. Teacher: Guillermo Moreno.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
What is inheritance? It is the ability to create a new class from an existing class.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
JAVA WORKSHOP SESSION – 3 PRESENTED BY JAYA RAO MTech(CSE) NEWTON’S INSTITUTE OF ENGINEERING 1.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
MIT AITI 2004 – Lecture 12 Inheritance. What is Inheritance?  In the real world: We inherit traits from our mother and father. We also inherit traits.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
INHERITANCE : Extending Classes. Rickshaw cart Bus Car Pulled Vehicles Inheritance Inheritance Vehicles Inheritance is the capability of one class of.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
CS 2430 Day 9. Announcements Quiz 2.1 this Friday Program 2 due this Friday at 3pm (grace date Sunday at 10pm)
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Topics Inheritance introduction
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
Types of Inheritance in C++. In C++ we have 5 different types of inheritance: – Single Inheritance – Multiple Inheritance – Hierarchical Inheritance –
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
Software Technology - I Classes Objects Methods (Cont.) A Baby is a Monkey.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
BY:- TOPS Technologies
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Inheritance. Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object Inheritance represents the IS-A.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
OOPM. Java Array Array is a collection of similar type of elements that have contiguous memory location. Java array is an object the contains elements.
Modern Programming Tools And Techniques-I
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Lecture 12 Inheritance.
Inheritance in Java Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea behind.
Inheritance and Polymorphism
Introduction to Programming with Java
Inheritance AKEEL AHMED.
Week 8 Lecture -3 Inheritance and Polymorphism
Programming in Java Text Books :
Modern Programming Tools And Techniques-I Inheritance
Inheritance Visit for more Learning Resources.
Interface.
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Programming Behnam Hatami Fall 2017.
OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS
Sampath Kumar.S Assistant Professor/IT, SECE
Inheritance Inheritance is a fundamental Object Oriented concept
Inheritance Cse 3rd year.
Java Programming, Second Edition
Inheritance.
Inheritance and Polymorphism
Chapter 11 Inheritance and Polymorphism Part 1
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

Java Inheritance in Java

Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea behind inheritance is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you reuse (or inherit) methods and fields, and you add new methods and fields to adapt your new class to new situations. Inheritance represents the IS-A relationship.

Why use Inheritance? For Method Overriding (So Runtime Polymorphism). For Code Reusability.

Syntax of Inheritance class Subclass-name extends Superclass-name { //methods and fields } The keyword extends indicates that you are making a new class that derives from an existing class. In the terminology of Java, a class that is inherited is called a superclass. The new class is called a subclass.

Understanding the simple example of inheritance

As displayed in the above figure, Programmer is the subclass and Employee is the superclass. Relationship between two classes is Programmer IS-A Employee.It means that Programmer is a type of Employee.

class Employee{ float salary=40000; } class Programmer extends Employee{ int bonus=10000; public static void main(String args[]){ Programmer p=new Programmer(); System.out.println("Programmer salary is:"+p.salary); System.out.println("Bonus of Programmer is:"+p.bonus); } Output:Programmer salary is: Bonus of programmer is:10000

Types of Inheritance On the basis of class, there can be three types of inheritance: single, multilevel and hierarchical. Multiple and Hybrid is supported through interface only. We will learn about interfaces later.

Multiple inheritance is not supported in java in case of class. When a class extends multiple classes i.e. known as multiple inheritance. For Example:

Que) Why multiple inheritance is not supported in java? To reduce the complexity and simplify the language, multiple inheritance is not supported in java. For example: class A{ void msg(){System.out.println("Hello");} } class B{ void msg(){System.out.println("Welcome");} } class C extends A,B{//suppose if it were Public Static void main(String args[]){ C obj=new C(); obj.msg();//Now which msg() method would be invoked? }