Inheritance

283 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
283
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×