SlideShare une entreprise Scribd logo
1  sur  27
Java Inheritance




                   1
 On the surface, inheritance is a code re-use
 issue.
   we can extend code that is already written in a
   manageable manner.
 Inheritance is more
   it supports polymorphism at the language level




                                                      2
 Take an existing object type (collection of
 fields and methods) and extend it.
   create a special version of the code without re-
    writing any of the existing code (or even explicitly
    calling it!).
   End result is a more specific object type, called the
    sub-class / derived class / child class.
   The original code is called the superclass / parent
    class / base class.

                                                            3
   Employee: name, email, phone
     FulltimeEmployee: also has salary, office, benefits, …
      ▪ Manager: CompanyCar, can change salaries, rates contracts,
        offices, etc.
     Contractor: HourlyRate, ContractDuration, …


   A manager is a special kind of FullTimeEmployee,
    which is a special kind of Employee.


                                                                     4
 Create code that deals with general object
  types, without the need to know what
  specific type each object is.
 Generate a list of employee names:
   all objects derived from Employee have a name
    field since Employee has a name field
   no need to treat managers differently from
    anyone else.

                                                    5
 The real power comes with
  methods/behaviors.
 A better example:
  shape object types used by a drawing program.
  we want to be able to handle any kind of shape
   someone wants to code (in the future).
  we want to be able to write code now that can
   deal with shape objects (without knowing what
   they are!).

                                                    6
   Shape:
     color, layer    fields

     draw()          draw itself on the screen

     calcArea()      calculates it's own area.

     serialize()      generate a string that can be saved and
      later used to re-generate the object.


                                                                 7
Each could be a kind of shape
 Rectangle
              (could be specializations of the
              shape class).
 Triangle

              Each knows how to draw itself,
 Circle      etc.


              Could write code to have all
              shapes draw themselves, or save
              the whole collection to a file.

                                                 8
class classname {
   field declarations
   { initialization code }
   Constructors
   Methods
}




                             9
 Abstract modifier means that the class can be
 used as a superclass only.
   no objects of this class can be created.
   can have attributes, even code
    ▪ all are inherited
    ▪ methods can be overridden
 Used in inheritance hierarchies



                                                  10
   private/protected/public:
     protected means private to all but subclasses
     what if none of these specified?
   abstract: no implementation given, must be
    supplied by subclass.
     the class itself must also be declared abstract
   final: the method cannot be changed by a
    subclass (no alternative implementation can be
    provided by a subclass).


                                                        11
Interesting Method Modifiers
       (that have nothing to do with this slide set)

• native: the method is written in some local
  code (C/C++) - the implementation is not
  provided in Java (recall assembler routines
  linked with C)
• synchronized: only one thread at a time
  can call the method (later)



                                                       12
 When one object type depends on another,
 the relationship could be:
   is-a
   has-a
 Sometimes it's hard to define the
 relationship, but in general you use
 composition (aggregation) when the
 relationship is has-a


                                             13
 One class has instance variables that refer to
  object of another.
 Sometimes we have a collection of objects,
  the class just provides the glue.
   establishes the relationship between objects.
 There is nothing special happening here (as
 far as the compiler is concerned).


                                                    14
 One object type is defined as being a special
  version of some other object type.
   a specialization.
 The more general class is called:
   base class, super class, parent class.
 The more specific class is called:
   derived class, subclass, child class.



                                                  15
 A derived class object is an object of the base
 class.
   is-a, not has-a.
   all fields and methods are inherited.
 The derived class object also has some stuff
 that the base class does not provide (usually).



                                                    16
 Two kinds:
  implementation: the code that defines methods.
  interface: the method prototypes only.


 Other OOP languages often provide the
 same capabilities (but not as an explicit
 option).


                                                    17
 Derived class inherits the implementations of
  all methods from base class.
   can replace some with alternatives.
   new methods in derived class can access all non-
   private base class fields and methods.

 This is similar to (simple) C++ inheritance.



                                                       18
 Can use super() to access all (non-private)
 superclass methods.
   even those replaced with new versions in the
   derived class.
 Can use super() to call base class
 constructor.
   use arguments to specify desired constructor



                                                   19
 You can't extend more than one class!
   the derived class can't have more than one base
   class.

 You can do multiple inheritance with interface
 inheritance.



                                                      20
   A object of a derived class can be cast as an object
    of the base class.
     this is much of the power!
   When a method is called, the selection of which
    version of method is run is totally dynamic.
     overridden methods are dynamic.

Note: Selection of overloaded methods is done at compile time. There are
  some situations in which this can cause confusion.



                                                                           21
 Granddaddy of all Java classes.

 All methods defined in the class Object are
 available in every class.

 Any object can be cast as an Object.




                                                22
 An interface is a definition of method
  prototypes and possibly some constants
  (static final fields).
 An interface does not include the
  implementation of any methods, it just
  defines a set of methods that could be
  implemented.


                                           23
 A class can implement an interface, this
 means that it provides implementations for
 all the methods in the interface.

 Java classes can implement any number of
 interfaces (multiple interface inheritance).



                                                24
   Creation (definition) of interfaces can be done using
    inheritance:
     one interface can extend another.

   Sometimes interfaces are used just as labeling
    mechanisms:
     Look in the Java API documentation for interfaces like
      Cloneable.
   Example: BubbleSort w/ SortInterfaceDemo


                                                               25
ou
     k   y
  a n
Th

                26
?

    27

Contenu connexe

Tendances

Tendances (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Dacj 2-1 a
Dacj 2-1 aDacj 2-1 a
Dacj 2-1 a
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 

Similaire à Java Inheritance Explained

Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.pptSeethaDinesh
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1javatrainingonline
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questionssatish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questionssatish reddy
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.Questpond
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 

Similaire à Java Inheritance Explained (20)

Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
C#
C#C#
C#
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Intervies
InterviesIntervies
Intervies
 
Pocket java
Pocket javaPocket java
Pocket java
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Core java questions
Core java questionsCore java questions
Core java questions
 
C# question answers
C# question answersC# question answers
C# question answers
 

Dernier

4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 

Dernier (20)

4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 

Java Inheritance Explained

  • 2.  On the surface, inheritance is a code re-use issue.  we can extend code that is already written in a manageable manner.  Inheritance is more  it supports polymorphism at the language level 2
  • 3.  Take an existing object type (collection of fields and methods) and extend it.  create a special version of the code without re- writing any of the existing code (or even explicitly calling it!).  End result is a more specific object type, called the sub-class / derived class / child class.  The original code is called the superclass / parent class / base class. 3
  • 4. Employee: name, email, phone  FulltimeEmployee: also has salary, office, benefits, … ▪ Manager: CompanyCar, can change salaries, rates contracts, offices, etc.  Contractor: HourlyRate, ContractDuration, …  A manager is a special kind of FullTimeEmployee, which is a special kind of Employee. 4
  • 5.  Create code that deals with general object types, without the need to know what specific type each object is.  Generate a list of employee names:  all objects derived from Employee have a name field since Employee has a name field  no need to treat managers differently from anyone else. 5
  • 6.  The real power comes with methods/behaviors.  A better example:  shape object types used by a drawing program.  we want to be able to handle any kind of shape someone wants to code (in the future).  we want to be able to write code now that can deal with shape objects (without knowing what they are!). 6
  • 7. Shape:  color, layer fields  draw() draw itself on the screen  calcArea() calculates it's own area.  serialize() generate a string that can be saved and later used to re-generate the object. 7
  • 8. Each could be a kind of shape  Rectangle (could be specializations of the shape class).  Triangle Each knows how to draw itself,  Circle etc. Could write code to have all shapes draw themselves, or save the whole collection to a file. 8
  • 9. class classname { field declarations { initialization code } Constructors Methods } 9
  • 10.  Abstract modifier means that the class can be used as a superclass only.  no objects of this class can be created.  can have attributes, even code ▪ all are inherited ▪ methods can be overridden  Used in inheritance hierarchies 10
  • 11. private/protected/public:  protected means private to all but subclasses  what if none of these specified?  abstract: no implementation given, must be supplied by subclass.  the class itself must also be declared abstract  final: the method cannot be changed by a subclass (no alternative implementation can be provided by a subclass). 11
  • 12. Interesting Method Modifiers (that have nothing to do with this slide set) • native: the method is written in some local code (C/C++) - the implementation is not provided in Java (recall assembler routines linked with C) • synchronized: only one thread at a time can call the method (later) 12
  • 13.  When one object type depends on another, the relationship could be:  is-a  has-a  Sometimes it's hard to define the relationship, but in general you use composition (aggregation) when the relationship is has-a 13
  • 14.  One class has instance variables that refer to object of another.  Sometimes we have a collection of objects, the class just provides the glue.  establishes the relationship between objects.  There is nothing special happening here (as far as the compiler is concerned). 14
  • 15.  One object type is defined as being a special version of some other object type.  a specialization.  The more general class is called:  base class, super class, parent class.  The more specific class is called:  derived class, subclass, child class. 15
  • 16.  A derived class object is an object of the base class.  is-a, not has-a.  all fields and methods are inherited.  The derived class object also has some stuff that the base class does not provide (usually). 16
  • 17.  Two kinds:  implementation: the code that defines methods.  interface: the method prototypes only.  Other OOP languages often provide the same capabilities (but not as an explicit option). 17
  • 18.  Derived class inherits the implementations of all methods from base class.  can replace some with alternatives.  new methods in derived class can access all non- private base class fields and methods.  This is similar to (simple) C++ inheritance. 18
  • 19.  Can use super() to access all (non-private) superclass methods.  even those replaced with new versions in the derived class.  Can use super() to call base class constructor.  use arguments to specify desired constructor 19
  • 20.  You can't extend more than one class!  the derived class can't have more than one base class.  You can do multiple inheritance with interface inheritance. 20
  • 21. A object of a derived class can be cast as an object of the base class.  this is much of the power!  When a method is called, the selection of which version of method is run is totally dynamic.  overridden methods are dynamic. Note: Selection of overloaded methods is done at compile time. There are some situations in which this can cause confusion. 21
  • 22.  Granddaddy of all Java classes.  All methods defined in the class Object are available in every class.  Any object can be cast as an Object. 22
  • 23.  An interface is a definition of method prototypes and possibly some constants (static final fields).  An interface does not include the implementation of any methods, it just defines a set of methods that could be implemented. 23
  • 24.  A class can implement an interface, this means that it provides implementations for all the methods in the interface.  Java classes can implement any number of interfaces (multiple interface inheritance). 24
  • 25. Creation (definition) of interfaces can be done using inheritance:  one interface can extend another.  Sometimes interfaces are used just as labeling mechanisms:  Look in the Java API documentation for interfaces like Cloneable.  Example: BubbleSort w/ SortInterfaceDemo 25
  • 26. ou k y a n Th 26
  • 27. ? 27