Sampath Kumar.S Assistant Professor/IT, SECE

Slides:



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

Chapter 1 Inheritance University Of Ha’il.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
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.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
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.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
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.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
CS 2430 Day 9. Announcements Quiz 2.1 this Friday Program 2 due this Friday at 3pm (grace date Sunday at 10pm)
Topics Inheritance introduction
Interfaces and Polymorphism CS 162 (Summer 2009).
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
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.
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
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.
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
Polymorphism.
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
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
Sampath Kumar S Assistant Professor, SECE
Inherited Classes in Java
Advanced Programming Behnam Hatami Fall 2017.
OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS
Sampath Kumar S Assistant Professor, SECE
Sampath Kumar S Assistant Professor, SECE
S.VIGNESH Assistant Professor, SECE
Method Overloading in JAVA
Sampath Kumar S Assistant Professor, SECE
Inheritance Inheritance is a fundamental Object Oriented concept
Method Overriding in Java
Sampath Kumar S Assistant Professor, SECE
Inheritance Cse 3rd year.
Java Programming, Second Edition
Sampath Kumar S Assistant Professor, SECE
Class Inheritance Concept of Inheritance Java keywords
Inheritance.
Inheritance and Polymorphism
Sampath Kumar S Assistant Professor, SECE
Chapter 11 Inheritance and Polymorphism Part 1
Sampath Kumar S Assistant Professor, SECE
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Inheritance and Polymorphism
Presentation transcript:

Sampath Kumar.S Assistant Professor/IT, SECE Inheritance in JAVA Sampath Kumar.S Assistant Professor/IT, SECE

Inheritance in Java 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   }   Note: 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.

Example of Inheritance

Example Program: 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:40000.0 Bonus of programmer is:10000

Types of Inheritance Three (Basic)types of Inheritance are there: Note: Multiple inheritance is not supported in java in case of class.

Multiple and Hybrid Note: Multiple and Hybrid is supported through interface only.

Why multiple inheritance is not supported in java? class A { void msg() { System.out.println("Hello"); } } class B { 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?

02-01-2019 Sampath Kumar.S, AP/IT

02-01-2019 Thank You  Sampath Kumar.S, AP/IT