Your SlideShare is downloading. ×
0
Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocumen...
Inheritance in Java        Ashwin Anand V        Email:ashwinanand99@gmail.com        Facebook id:ashwinanand99@gmail.com
InheritanceA class can extend another class,inheriting all its data members andmethods while redefining some ofthem and/or...
Inheritance Terminology:  subclass                        superclass     or            extends             orderived class...
Inheritance (cont’d)Example:                        Dancer           MaleDancer        FemaleDancer
Inheritance (cont’d)Constructors are not inherited. TheFemaleDancer class only adds a constructor:public class FemaleDance...
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,...
Inheritance may be used to define ahierarchy of classes in an application:             Object                             ...
• If this presentation helped you, please visit  our page facebook.com/baabtra and like it.  Thanks in advance.• www.baabt...
Thank you
Contact Us
Inheritance
Upcoming SlideShare
Loading in...5
×

Inheritance

209

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
209
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Inheritance"

  1. 1. Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  2. 2. Inheritance in Java Ashwin Anand V Email:ashwinanand99@gmail.com Facebook id:ashwinanand99@gmail.com
  3. 3. InheritanceA class can extend another class,inheriting all its data members andmethods while redefining some ofthem and/or adding its own.Inheritance represents the is arelationship between data types. Forexample: a FemaleDancer is aDancer.
  4. 4. Inheritance Terminology: subclass superclass or extends orderived class base classpublic class FemaleDancer extends Dancer{ ...}
  5. 5. Inheritance (cont’d)Example: Dancer MaleDancer FemaleDancer
  6. 6. Inheritance (cont’d)Constructors are not inherited. TheFemaleDancer 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); }}
  7. 7. Inheritance (cont’d)Example: Foot MaleFoot FemaleFoot
  8. 8. public class FemaleFoot extends Foot{ public FemaleFoot(String side, int x, int y, int dir) { super(side, x, y, dir); // calls Foots constructor } // public void drawLeft(Graphics g) { ... Supplies methods that } are abstract in public void drawRight(Graphics g) Foot: { ... }}
  9. 9. Inheritance may be used to define ahierarchy of classes in an application: Object Foot MaleFoot FemaleFoot MaleLeftFoot MaleRightFoot FemaleLeftFoot FemaleRightFoot
  10. 10. • 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
  11. 11. Thank you
  12. 12. Contact Us
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×