Preview

Java Inheritance

Powerful Essays
Open Document
Open Document
4859 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java Inheritance
CSCI 2912 JAVA NOTES a supplement to the textbook
Copyright @ 2009-2011 Dr. Milica Barjaktarovic
All Rights Reserved

Chapter 11
Inheritance and Polymorphism
Table of Contents

1. Inheritance and Polymorphism
This is what makes OO interesting.
Inheritance is useful when there is a common set of characteristics for many different classes. This “base set” becomes the superclass, or base class.
Other classes can inherit this basic set and also add their own unique methods and fields. Such classes are called subclasses, or derived classes.
Subclass “is-a” instance of superclass, i.e. a special case of the superclass.

Examples: conceptually
Bee IS an insect. Cricket IS an insect. Cockroach IS an insect. Moskito IS an insect. Etc.
Superclass
Subclass
Subclass
Subclass
Subclass
Insect: hasAntenae liesEggs

Bee hasWings eats Honey canBuzz canFly canSting Cricket canJump canChirp eats? Cockroach hasWings canFly canCrawl eatsHumanFood
Moskito
hasWings canFly eatsBlood canBuzzz canInfect

Dog has4Feet hasTail hasWhiskers hasFur hasLongNose canBark

GoldenRetreiver isLarge isSilky
Chiuaua
isSmall isNotFuzzy Malamute isLarge hasThickFur

Pomeranian isSmall hasLongFur hasBushyTail Cat has4feet hasTail hasWhiskers hasFur hasFlatFace canMeow

Persian isFluffy isSmall isHome Siamese hasBlueEyes isNotFuzzy hasBeigeBodywithBrownTrim isSmall isHome Tabby hasStripes isSmall isHalfWild Tiger isLarge hasStripes isWild How to code inheritance
The base class and all derived classes are “classes as usual”. What connects them is that all derived classes must have “extends” clause in the declaration. public class Leopard extends Cat public class Siamese extends Cat public class Tabby extends Cat
If we don’t put the word “extend”, by default every class in Java inherits from Object class, i.e. by default, every class is specified as whatever_access class Name extends

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Dna Worksheet Sci/230

    • 314 Words
    • 2 Pages

    passed on to the organisms from its parents. The phenotype is the process of determining which…

    • 314 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    IPv4 has different class types: A,B,C,D and E. Class A, Class B, and Class C are the three classes of addresses used on IP networks in common practice. Class D addresses are reserved for multicast. Class E addresses are simply reserved, meaning they should not be used on IP networks (used on a limited basis by some research organizations for experimental purposes). IPv4 has different class types: A,B,C,D and E. Class A, Class B, and Class C…

    • 981 Words
    • 4 Pages
    Powerful Essays
  • Good Essays

    Bees are amazing. They are so cool. Bees have been around almost one hundred million years. There are many different kinds of bees. Bees see flowers different from what people do. Bees live in different places. They have a head,wings,abdomen,stinger,legs,thorak mouthparts,and a antena. Bees are nifty insects.…

    • 160 Words
    • 1 Page
    Good Essays
  • Best Essays

    Background theory four levels are labeled elemental traits, compound traits, situational traits, and surface traits.…

    • 1503 Words
    • 7 Pages
    Best Essays
  • Powerful Essays

    5e Monk Guide

    • 7976 Words
    • 16 Pages

    dependent) classes in the game. In older editions, there was sadly almost no reason to play a…

    • 7976 Words
    • 16 Pages
    Powerful Essays
  • Good Essays

    Basic level type- an example of a type of concepts around which similar concepts are organized, such as “dog,” “cat” or “pear.”…

    • 959 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Leaf Cutter Bees

    • 560 Words
    • 3 Pages

    Leaf cutter bees, play a big part in the world. Not very many people know of their existence or what they actually do. They are very interesting little insects starting from there looks, actions, and how important their job is as a Leaf Cutter Bee.…

    • 560 Words
    • 3 Pages
    Good Essays
  • Better Essays

    Archetypes - 2

    • 1167 Words
    • 5 Pages

    Cited: "Archetypes: Defined and Explained with Examples." hubpages. HubPages Inc., 23 Jun 2013. Web. 23 Sep 2012. <http://sandrabusby.hubpages.com/hub/Archetypes-Defined-and-Explained-with-Examples>.…

    • 1167 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    Principle of Type - Type refers to the activity you choose in order to achieve an appropriate training response.…

    • 527 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Different ways would apply when I establish the ground rule of the class. The main method I use…

    • 317 Words
    • 2 Pages
    Good Essays
  • Better Essays

    Honey Bees Disappearance

    • 976 Words
    • 4 Pages

    Bees are flying insects that are related to wasps and ants. Those insects are mostly known for their role of pollination and for producing honey and beeswax. There are about 20,000 different species of bees around the world, and every single species of bees live in colonies where there are three types of bees: the queen, the worker, and the drone.…

    • 976 Words
    • 4 Pages
    Better Essays
  • Satisfactory Essays

    To crafit that a has a created element , that you can always adapt and change things…

    • 775 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Domains of Culture

    • 685 Words
    • 3 Pages

    2. inheritance. (n.d.). Collins English Dictionary - Complete & Unabridged 10th Edition. Retrieved April 29, 2012, from Dictionary.com website: http://dictionary.reference.com/browse/inheritance…

    • 685 Words
    • 3 Pages
    Good Essays
  • Best Essays

    Who would think that an insect less than an inch big could be of so much importance to the human society? Throughout the history of mankind, the Western Honey Bee has proven to be of many uses to the human society. The study of the honey bee has shown the true intricacy and efficiency of their colony. Each member of the colony works together in a nearly flawless environment of productivity. For these reasons, and many more, the Western honey bee has proven itself to be one of the most fascinating and useful insects there has ever been.…

    • 3039 Words
    • 13 Pages
    Best Essays
  • Satisfactory Essays

    online auction

    • 347 Words
    • 2 Pages

    The javax.swing.plaf package consists of abstract classes derived from ComponentUI, and the classes in the javax.swing.plaf.basic package extend these abstract classes to implement the Basic look-and-feel. This is the set of UI delegates that all other look-and-feel classes are expected to use as a base for building off of. The Basic look-and-feel cannot be used on its own because BasicLookAndFeel is an abstract class. There are three pluggable look-and-feel implementations derived from the Basic look-and-feel:…

    • 347 Words
    • 2 Pages
    Satisfactory Essays

Related Topics