More Features of Java - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

More Features of Java

Description:

More Features of Java Inheritance Interfaces Nested Classes Packages Inheritance extends: keyword to indicate a class is a subclass of another (general to specific ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 17
Provided by: Russell183
Category:
Tags: features | java | more | network

less

Transcript and Presenter's Notes

Title: More Features of Java


1
More Features of Java
  • Inheritance
  • Interfaces
  • Nested Classes
  • Packages

2
Inheritance
  • extends keyword to indicate a class is a
    subclass of another (general to specific)
  • square extends rectangle
  • Can only be one superclass for each subclass
    (single inheritance)
  • Object class is most general of all classes
  • State and behavior is inherited from all ancestors

3
What is Inherited
  • All public and protected superclass members
  • Unspecified superclass members
  • Dont inherit overridden members
  • Dont inherit private members

4
Hiding Variables and Overriding methods
  • Hide variables in superclass by redeclaring in
    subclass (careful)
  • Refer to superclass variable with super keyword
  • Override Redefine method in subclass
  • Return type, method name, number and type of
    arguments must be the same

5
  • Can have a different throws clause
  • Can provide more access but not less
  • Dont have to completely override method.Just
    add functionality. Simply class overridden
    method using super keyword
  • Cant override final or static methods
  • Must override abstract methods

6
Object
  • Methods to override
  • clone must implement Cloneable interface to
    create objects from other objects of same type
  • equals Compare to objects for equality
  • finalize Clean up before garbage collection
  • toString Returns string representation of
    object.
  • getClass returns runtime representation of
    object (Class object)

7
Etc...
  • final classes and methods for security and design
    goals.
  • Abstract classes and methods for conceptual
    constructs

8
Interfaces
  • To define a set of behaviors that can be
    implemented by any class
  • A name collection of method definitions without
    implementations plus constant declarations
  • Protocols is another name.
  • Unlike Abstract Class, doesnt force class
    relationship on users

9
(No Transcript)
10
(No Transcript)
11
(No Transcript)
12
(No Transcript)
13
More on Interfaces
  • Classes can implement multiple interfaces
  • Not multiple inheritance
  • Inherits only constants from interface
  • Cannot inherit method implementations
  • Interface hierarchy independent of class
  • Interfaces cannot grow

14
Packages
  • A package is a collection of related classes and
    interfaces that provides access protection and
    namespace management.
  • package statement at top of source code
  • Refer to by long name (file pathname)
  • import package or package member
  • class path is list of directories to search for
    class files

15
Nested Classes
  • Defining a class as a member of another class
  • Has access to all of enclosing class members
  • Static nested classes (class)
  • Inner classes (instance)

16
Inner Classes
  • Anonymous Classes
Write a Comment
User Comments (0)
About PowerShow.com