Reading: - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Reading:

Description:

If a class has a constructor with only one parameter ... feline. primate. dog. wolf. fox. lion. tiger. puma. chimpanzee. gorilla. orangutan. Dr. M. Moussavi ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 15
Provided by: mous1
Category:
Tags: feline | reading

less

Transcript and Presenter's Notes

Title: Reading:


1
  • Reading
  • 5.7, 6.1, 6.4, 7.3. 5

2
Type Conversion
  • Implicit Type Conversion
  • Means it happens even you dont ask for it.
  • int j 34
  • double d
  • d j / 2.0
  • Void fun (double x)
  • fun (j)
  • Explicit Type Conversion
  • Means it happens if you ask for it.
  • d double(j)/2

3
Type Conversion
  • If a class has a constructor with only one
    parameter that constructor will be used by the
    compiler for implicit type conversion .
  • For example
  • StringOne x CDC

4
Different Programming Approaches
  • Procedural
  • Object Based
  • Object Oriented

5
Class Relationships
  • Association
  • Composition
  • Inheritance

6
Composition
  • Composition represents a has-a relationship
    between two classes. In other word composition is
    implemented by making one class a member of the
    other class

7
Composition (Continued)
  • Composition denotes a whole/part relationship,
    with the ability to navigate from whole
    (aggregate) to its parts (attributes).
  • The composition may or may not denote physical
    containment.
  • Example The relationship between a shareholder
    and his shares is not physical containment.

8
Class Hierarchy
  • Classes are related by inheritance
  • A subclass inherits behavior and structure from
    its super-class.
  • A subclass also augments or redefines the
    behavior and structure of its super-class.
  • Also known as generalization/specialization
    hierarchy.

9
Class Hierarchy (continued)
  • Single inheritance
  • Where subclasses can have only one immediate
    super-class.
  • E.g.

10
Inheritance
  • Inheritance is a relationship among classes where
    a subclass inherits the structure and behavior of
    its super-class.
  • Defines the is a or generalization/specializatio
    n hierarchy.
  • Structure instance variables.
  • Behavior instance methods.

11
Inheritance (continued)
  • A subclass may augment the existing structure and
    behavior of its super-class.
  • A subclass may constrain or restrict the behavior
    inherited from its super-class.
  • Single inheritance any class has at most one
    super-class.
  • Multiple Inheritance where a subclass may have
    more than one super-class.

12
Class derivation
  • In order to derive a class, the following two
    extensions to the class syntax are necessary
  • class head is modified to allow a derivation list
    of classes from which to inherit members
  • class Window public Screen
  • An additional class level, that of protected, is
    provided. A protected class member behaves as a
    public member to a derived class

13
Class derivation (Continued)
  • A super-classs instance variables are directly
    accessible to the subclass if they are declared
    protected.
  • If declared private, these variables can only be
    accessed by sending messages to super (by
    invoking a super classs member function).

14
Class derivation - Example
class Student public Person public
Student() protected char id
  • class Person
  • public
  • Person()
  • protected
  • int age
  • char name
Write a Comment
User Comments (0)
About PowerShow.com