CS102_OOP - CS102OOP Inheritance, Polymorphism,...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
    CS102 – OOP Inheritance,  Polymorphism,  Interfaces & Abstract  classes. David Davenport Spring 2002
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Introduction Advantages of OOP Natural view/description of world Set of interacting objects  organised in classes & facilitates reuse Classes are reusable components which can be modified as needed Hierarchy of classes - inheritance
Background image of page 2
    One way to represent classes Without Inheritance Person name, dateOfBirth, wallet Student name, dateOfBirth, wallet, gpa,  dept, idCard, …
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Another way, using hierarchy/inheritance With Inheritance Person name, dateOfBirth, wallet Student gpa, dept, idCard, … is_a
Background image of page 4
    Inheritance Hierarchy Person name, dateOfBirth, wallet Student gpa, dept, idCard, … is_a Faculty salary, dept, officeHours … is_a UnderGrad Grad gradDate, … is_a is_a
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    {Student} gpa dept idCard Inheritance & Composition {Person} name dateOfBirth wallet {Wallet} owner cash {IDCard} name idNo picture has_a has_a is_a or has_a
Background image of page 6
    Inheritance All classes extend  Object class unless  otherwise specified Sub-classes can Add new properties &  methods Object Person Student Wallet IDCard Lise Undergrad Grad parent class child/sub class
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Example Java Code public class Person { String  name; Date    dateOfBirth; Wallet  wallet; public Person ( String name, Date dob) { this.name = name; dateOfBirth = dob; wallet = null; } public String getName() { return name; } }
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/14/2011 for the course CS 102 taught by Professor David during the Spring '08 term at Bilkent University.

Page1 / 19

CS102_OOP - CS102OOP Inheritance, Polymorphism,...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online