Preview

Lecture 2 Inheritance And Polymorphism

Good Essays
Open Document
Open Document
1037 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Lecture 2 Inheritance And Polymorphism
Inheritance and Polymorphism
Prepared by: Prof. Irysh Paulo R. Tipay, MSCS

Quote for the Day


“That's the thing about people who think they hate computers. What they really hate is lousy programmers.” ― Larry Niven

Recap!









What you already know…
In OOP, EVERYTHING is an OBJECT
A Class is a blueprint/model used for creating
Objects
An Object is an instance of a Class
Both Objects and Classes have an attribute and behaviour A class should have at least one Constructor.
A Constructor is used to set the default values of the attributes
A Class Diagram is a UML which is basically a graphical representation of a class

Inheritance



This is a way of relating 2 or more classes.
This is the idea of passing down the attributes and behaviours of the super class to the sub class. Super class – (base class,
SUPER CLASS parent class)

Sub class – (child class,
CLASS
derivedSUB class) This is the symbol used to show inheritance

Inheritance





Inheritance is an “is-a” relationship.
Student is a Person
Teacher is a Person



Cat is an Animal



Dog is a Fruit



Grape is a Fruit

Inheritance


Java supports single inheritance, meaning a super class can have multiple sub classes, but a sub class can only have one super class. SUPER CLASS

SUB CLASS

SUB CLASS

SUB CLASS

Inheritance


A sub class can be a super class of another class. CLASS A

CLASS B

CLASS C

Inheritance


Observe…
VEHICLE

CAR

Inheritance
Vehicle
- String color
- String bodyNumber
-String
numberOfWheels
+Vehicle()
+void accelerate();
+ void brake();

Car
- String plateNumber
- String mileage
+Car()
+void playMusic();
+ void enableGPS();

Car myCar = new Car( ); myCar.accelerate( );

In this Example, the Car class is able to inherit all the members of the
Vehicle class EXCEPT for its private members. The “extends” keyword public class Vechicle{ private String color; private String bodyNumber; private String numberOfWheels; public Vehicle(){ color = “blue”;
public

You May Also Find These Documents Helpful

  • Satisfactory Essays

    COMM 355 Assignment 2

    • 352 Words
    • 2 Pages

    1. The $2,400 gym membership is a non-taxable benefit. The $1,200 personal training cost is a taxable benefit.…

    • 352 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Psy300 Week 8

    • 760 Words
    • 4 Pages

    • Identify how you can encapsulate the data and processes you identified into an object-oriented design.…

    • 760 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    Genotype is the genetic make-up, the inheritable information, which comprises an individual organism. It is the code that is copied in reproduction and is passed from 1 generation to the next. It serves as the main guide in the growth, development and maintenance of a living organism; it also controls the formation of certain proteins and regulation of metabolism and synthesis. Alleles are alternative forms of a gene and genotype refer to a specific allele like hair color, height, skin tone, etc. These observable traits are the phenotype. Phenotype is the resulting characteristic of an encoded genotype; it is what we can see, it’s the physical appearance of an organism.…

    • 1144 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    Lecture Quiz 1

    • 287 Words
    • 2 Pages

    6) Assume that the body has been sectioned along three planes: (1) a median plane, (2) a frontal plane, and (3) a transverse plane made at the level of each of the organs listed below. which orans would not be visible in all three cases?…

    • 287 Words
    • 2 Pages
    Good Essays
  • Better Essays

    If a,b ∈F, then a+b=b+a. That is the elements a,b ∈F are commutative under addition. If…

    • 1619 Words
    • 7 Pages
    Better Essays
  • Satisfactory Essays

    The main concerns I have while conducting research, is knowing if the information is accurate for one, and does it really help me in my writing. With sites like Wikipedia, you have to assume they are not the only sites of their nature. While a lot of their information is correct, it may not be accurate or properly cited or documented. Others have to be doing the same thing, like urban dictionary among others. It makes me nervous unless I am on a .org or .gov website. Knowing if the information is truly helping my case, instead of hurting me is the other concern. Things can be taken out of context very easily, and either I, or the reader could mis-understand where I was going with something.…

    • 255 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    1. Two pure-breeding mutant plants produce white flowers. When they are crossed, all of the progeny have…

    • 857 Words
    • 7 Pages
    Satisfactory Essays
  • Satisfactory Essays

    i. No, the ratios should not show any particular pattern. Although it might be expected that dominant phenotypes will dominate among the individuals, it is not the case all the time. Consequently, there is not particular pattern being displayed here. As one can observe, the 1st, 4th and 5th traits show domination of the dominant phenotype. On the other hand, the 2nd and 3rd traits the recessive phenotype occurs at higher rates.…

    • 400 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Answers To Assignment 2 1

    • 2996 Words
    • 21 Pages

    Be Sure to submit these assignments by 09/27/2014 on BlackBoard, under “Assignment-Week 2. Answers must be labeled properly, with all pertinent information. No late submissions will be accepted.…

    • 2996 Words
    • 21 Pages
    Powerful Essays
  • Satisfactory Essays

    Assignment 205 Task a

    • 296 Words
    • 2 Pages

    I heard you were thinking of working in a care profession which is great I just wanted to fill you in on a few things which could help you.…

    • 296 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Assignment 201 task A

    • 591 Words
    • 3 Pages

    Aiii Give two reasons why it is important to observe the reactions of an individual using the service when you are communicating with them…

    • 591 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The Last Lecture was a very interesting and inspiring book to read. It focuses on living life more than death. The life that Randy Pausch lived was not only educational for his students but for himself and he hoped educational for his children. He reflected on his past and taught his student to live their childhood dreams. Pausch was trying to leave a legacy for his children not only through his last lecture but also in the way he looked at life.…

    • 752 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 4 Assignment 2

    • 1005 Words
    • 5 Pages

    Conducting actions irrelevant to their work, such as playing games, listening to music, watch videos, and etc.…

    • 1005 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    theories assignment 2

    • 719 Words
    • 2 Pages

    1. Samara demonstrates Horney’s “moving towards” neurosis meaning she deals with anxiety by an excessive interest in being accepted, needed, and approved of. We first learn this in the first paragraph where it says, “she is sensitive to the needs of others.” She is constantly looking for a boy to accept her and does all that she can to make sure he is happy. An example of this would be when she cooks him big dinners and only goes to see movies he will like to. She get very bad anxiety when her boyfriends would hang out with other girls, which would lead her to become very possessive.…

    • 719 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    You have submitted this Assignment on Sun 5 Aug 2012 2:32:29 AM PDT. You achieved a score of 90.00 out of 100.00.…

    • 1422 Words
    • 6 Pages
    Satisfactory Essays