M08640010120114034M0864POK-p08 Inheritance

Embed Size (px)

Citation preview

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    1/14

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    2/14

    InheritanceSession 8

    Course : M0864 - Programming I

    Year : September 2011

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    3/14

    Bina Nusantara

    Learning Outcomes

    At the end of this session, the students will be

    able to :

    Apply the concept of inheritance on GUI in

    Java

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    4/14

    Bina Nusantara

    Lecture Outline

    Inheritance (extends)

    Overriding VS Overloading.

    Inheritance Components

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    5/14

    Inheritance

    Inheritence from superclass to subclass.

    Subclass inherits and given the right to acces datamember ( fields/variables, methods, and nested classes

    ) that are existed in the Superclass except constructor.

    Able to add new data member on Subclass.

    Use extendsto access the parent class.

    Bina Nusantara

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    6/14

    Inheritance

    Bina Nusantara

    A Subclass inherits all access to publicandprotectedfrom its Superclass, the packageofsubclass is not a concern.

    If a subclass has the same packageassuperclass then subclass will inherits memberpackage-private from its superclassas well.

    Is not allowed to receive multiple inheritancefrom more than one parents.

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    7/14

    Inheritance

    In Java GUI programming, all class is definitely

    inheritance, usually are inheritance from JFrame

    GUI classes in Java can be modified.

    Bina Nusantara

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    8/14

    Overriding VS Overloading

    Overriding :

    Subclass modifies method that has been defined by superclass.

    Function that is declared by subclass should have the same

    signature(name, numbers and data types of parameters) and

    return value method with the existing one in the superclass

    Overloading :

    More than one functions that have the same name with the

    existing one in the superclass.

    Function that is declared in subclass does not have to have thesame signature (name, numbers and data types of parameter)

    and return value method with the existing one in the superclass

    Bina Nusantara

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    9/14

    Inherite Components

    Self-create class that is an inheritance from one

    component and contains of other GUI components

    Generally are inheritance from class Container (JFrame,

    JPaneland JApplet) that is most often to be inherited.

    Usually is used to create a user control component.

    Bina Nusantara

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    10/14

    Inherite Components

    Bina Nusantara

    Reusability class.

    In designing User Interface (UI) Form, organize UIcomponents that have the functionality in 1 group in a

    class that is handled by a Containerclasssuch as

    JPanel.

    Easy to modify screen design.

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    11/14

    Inherite Components Sample :

    Bina Nusantara

    MyInformationclass is a subclass of

    JPaneland consists of components to

    create a user control

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    12/14

    Inherite Components Sample in the caller class :

    Bina Nusantara

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    13/14

    Inherite Components

    Output

    Bina Nusantara

    Is an object of

    Class MyInformation

  • 8/11/2019 M08640010120114034M0864POK-p08 Inheritance

    14/14

    Bina Nusantara

    Reference

    Introduction to java programming comprehensive version, Chapter

    10, Page 357

    Software Java Solutions, Chapter 8, Page 467

    http://home.cogeco.ca/~ve3ll/jatutor5.htm

    http://download.oracle.com/javase/tutorial/java/IandI/subclasses.htm

    l

    http://download.oracle.com/javase/tutorial/java/concepts/interface.ht

    ml

    http://home.cogeco.ca/~ve3ll/jatutor5.htmhttp://download.oracle.com/javase/tutorial/java/IandI/subclasses.htmlhttp://download.oracle.com/javase/tutorial/java/IandI/subclasses.htmlhttp://download.oracle.com/javase/tutorial/java/concepts/interface.htmlhttp://download.oracle.com/javase/tutorial/java/concepts/interface.htmlhttp://download.oracle.com/javase/tutorial/java/concepts/interface.htmlhttp://download.oracle.com/javase/tutorial/java/concepts/interface.htmlhttp://download.oracle.com/javase/tutorial/java/IandI/subclasses.htmlhttp://download.oracle.com/javase/tutorial/java/IandI/subclasses.htmlhttp://home.cogeco.ca/~ve3ll/jatutor5.htm