SlideShare una empresa de Scribd logo
1 de 25
1
D.SEETHALAKSHMI
Assistant Professor
Department of Computer Applications
Bon Secours College for Women
 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
 Rectangle
 Triangle
 Circle
8
Each could be a kind of shape
(could be specializations of the
shape class).
Each knows how to draw itself,
etc.
Could write code to have all
shapes draw themselves, or save
the whole collection to a file.
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
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)
 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

Más contenido relacionado

Similar a Inheritance in java.ppt

Similar a Inheritance in java.ppt (20)

Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
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
 
Inheritance
InheritanceInheritance
Inheritance
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
C# question answers
C# question answersC# question answers
C# question answers
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Java basics
Java basicsJava basics
Java basics
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
Oops
OopsOops
Oops
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Java 06
Java 06Java 06
Java 06
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Application package
Application packageApplication package
Application package
 

Más de SeethaDinesh

Input Devices.pptx
Input Devices.pptxInput Devices.pptx
Input Devices.pptxSeethaDinesh
 
Generations of Computers.ppt
Generations of Computers.pptGenerations of Computers.ppt
Generations of Computers.pptSeethaDinesh
 
Arrays in JAVA.ppt
Arrays in JAVA.pptArrays in JAVA.ppt
Arrays in JAVA.pptSeethaDinesh
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxSeethaDinesh
 
Cloud Computing Basics.pptx
Cloud Computing Basics.pptxCloud Computing Basics.pptx
Cloud Computing Basics.pptxSeethaDinesh
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
 
Greedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.pptGreedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.pptSeethaDinesh
 
Structure and Union.ppt
Structure and Union.pptStructure and Union.ppt
Structure and Union.pptSeethaDinesh
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docxSeethaDinesh
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
NME WPI UNIt 3.pptx
NME WPI UNIt 3.pptxNME WPI UNIt 3.pptx
NME WPI UNIt 3.pptxSeethaDinesh
 
NME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdfNME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdfSeethaDinesh
 
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdfSeethaDinesh
 

Más de SeethaDinesh (20)

Input Devices.pptx
Input Devices.pptxInput Devices.pptx
Input Devices.pptx
 
Generations of Computers.ppt
Generations of Computers.pptGenerations of Computers.ppt
Generations of Computers.ppt
 
Arrays in JAVA.ppt
Arrays in JAVA.pptArrays in JAVA.ppt
Arrays in JAVA.ppt
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
 
Cloud Computing Basics.pptx
Cloud Computing Basics.pptxCloud Computing Basics.pptx
Cloud Computing Basics.pptx
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Greedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.pptGreedy_Backtracking graph coloring.ppt
Greedy_Backtracking graph coloring.ppt
 
Structure and Union.ppt
Structure and Union.pptStructure and Union.ppt
Structure and Union.ppt
 
Shortest Path Problem.docx
Shortest Path Problem.docxShortest Path Problem.docx
Shortest Path Problem.docx
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
NME UNIT II.ppt
NME UNIT II.pptNME UNIT II.ppt
NME UNIT II.ppt
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
DW unit 3.pptx
DW unit 3.pptxDW unit 3.pptx
DW unit 3.pptx
 
DW unit 2.pdf
DW unit 2.pdfDW unit 2.pdf
DW unit 2.pdf
 
DW Unit 1.pdf
DW Unit 1.pdfDW Unit 1.pdf
DW Unit 1.pdf
 
NME WPI UNIt 3.pptx
NME WPI UNIt 3.pptxNME WPI UNIt 3.pptx
NME WPI UNIt 3.pptx
 
NME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdfNME UNIT I & II MATERIAL.pdf
NME UNIT I & II MATERIAL.pdf
 
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdf
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 

Inheritance in java.ppt

  • 1. 1 D.SEETHALAKSHMI Assistant Professor Department of Computer Applications Bon Secours College for Women
  • 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.  Rectangle  Triangle  Circle 8 Each could be a kind of shape (could be specializations of the shape class). Each knows how to draw itself, etc. Could write code to have all shapes draw themselves, or save the whole collection to a file.
  • 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. 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)
  • 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