SlideShare a Scribd company logo
1 of 13
Disclaimer:This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Inheritance in Java



        Ashwin Anand V
        Email:ashwinanand99@gmail.com
        Facebook id:ashwinanand99@gmail.com
Inheritance

A class can extend another class,
inheriting all its data members and
methods while redefining some of
them and/or adding its own.
Inheritance represents the is a
relationship between data types. For
example: a FemaleDancer is a
Dancer.
Inheritance Terminology:

  subclass                        superclass
     or            extends             or
derived class                     base class

public class FemaleDancer extends Dancer
{
  ...
}
Inheritance (cont’d)

Example:

                        Dancer




           MaleDancer        FemaleDancer
Inheritance (cont’d)
Constructors are not inherited. The
FemaleDancer class only adds a constructor:

public class FemaleDancer extends Dancer
{
  public FemaleDancer(String steps[],
                            int x, int y, int dir)
  {
    leftFoot = new FemaleFoot("left", x, y, dir);
    rightFoot = new FemaleFoot("right", x, y, dir);
    leftFoot.move(-Foot.getWidth() / 2, 0);
    rightFoot.move(Foot.getWidth() / 2, 0);
  }
}
Inheritance (cont’d)

Example:

                      Foot




           MaleFoot          FemaleFoot
public class FemaleFoot extends Foot
{

    public FemaleFoot(String side, int x, int y, int dir)
    {
      super(side, x, y, dir); // calls Foot's constructor
    }

    //

    public void drawLeft(Graphics g)
    {
      ...
                                           Supplies methods that
    }
                                           are abstract in
    public void drawRight(Graphics g)      Foot:
    {
      ...
    }
}
Inheritance may be used to define a
hierarchy of classes in an application:
             Object



                                   Foot



                 MaleFoot                 FemaleFoot



  MaleLeftFoot     MaleRightFoot     FemaleLeftFoot    FemaleRightFoot
• If this presentation helped you, please visit
  our page facebook.com/baabtra and like it.
  Thanks in advance.

• www.baabtra.com | www.massbaab.com |ww
  w.baabte.com
Thank you
Contact Us

More Related Content

Similar to Inheritance

Abstrac tinheritance polymorphism
Abstrac tinheritance polymorphismAbstrac tinheritance polymorphism
Abstrac tinheritance polymorphismHoang Nguyen
 
.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloadingDrRajeshreeKhande
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdfrd1742
 
IRJET- Inheritance in Java
IRJET- Inheritance in JavaIRJET- Inheritance in Java
IRJET- Inheritance in JavaIRJET Journal
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.MASQ Technologies
 

Similar to Inheritance (15)

Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
Abstract inheritpoly
Abstract inheritpolyAbstract inheritpoly
Abstract inheritpoly
 
Abstrac tinheritance polymorphism
Abstrac tinheritance polymorphismAbstrac tinheritance polymorphism
Abstrac tinheritance polymorphism
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
Poo java
Poo javaPoo java
Poo java
 
.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
IRJET- Inheritance in Java
IRJET- Inheritance in JavaIRJET- Inheritance in Java
IRJET- Inheritance in Java
 
Presentation 3.pdf
Presentation 3.pdfPresentation 3.pdf
Presentation 3.pdf
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Inheritance

  • 1.
  • 2. Disclaimer:This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Inheritance in Java Ashwin Anand V Email:ashwinanand99@gmail.com Facebook id:ashwinanand99@gmail.com
  • 4. Inheritance A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding its own. Inheritance represents the is a relationship between data types. For example: a FemaleDancer is a Dancer.
  • 5. Inheritance Terminology: subclass superclass or extends or derived class base class public class FemaleDancer extends Dancer { ... }
  • 6. Inheritance (cont’d) Example: Dancer MaleDancer FemaleDancer
  • 7. Inheritance (cont’d) Constructors are not inherited. The FemaleDancer class only adds a constructor: public class FemaleDancer extends Dancer { public FemaleDancer(String steps[], int x, int y, int dir) { leftFoot = new FemaleFoot("left", x, y, dir); rightFoot = new FemaleFoot("right", x, y, dir); leftFoot.move(-Foot.getWidth() / 2, 0); rightFoot.move(Foot.getWidth() / 2, 0); } }
  • 8. Inheritance (cont’d) Example: Foot MaleFoot FemaleFoot
  • 9. public class FemaleFoot extends Foot { public FemaleFoot(String side, int x, int y, int dir) { super(side, x, y, dir); // calls Foot's constructor } // public void drawLeft(Graphics g) { ... Supplies methods that } are abstract in public void drawRight(Graphics g) Foot: { ... } }
  • 10. Inheritance may be used to define a hierarchy of classes in an application: Object Foot MaleFoot FemaleFoot MaleLeftFoot MaleRightFoot FemaleLeftFoot FemaleRightFoot
  • 11. • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. • www.baabtra.com | www.massbaab.com |ww w.baabte.com