KEMBAR78
OOPS_AbstractClasses_explained__java.ppt
Abstract Classes
Session-4
● This module introduces patcipants to the
Abstract Classes
● Describes memory allocation to Subclass
objects .
● Difference between Abstract Classes and
Interfaces.
Module Overview
2
Objectives
•Able to create programs that has better
utilization of Memory.
•Participant should be able to create
programs that occupiest less memory and
better performance.
•Understanding allocation of memory to all
units of the program.
Abstract Classes
An abstract class is a class that is declared abstract and cannot be instantiated
but can be subclassed.
An abstract method is a method that is declared without an implementation .
Why Abstract Class?
An abstract class exists only to express the common properties of all its
subclasses.
A class that is not abstract is said to be concrete. You can create objects
belonging to a concrete class, but not to an abstract class. A variable whose type
is given by an abstract class can only refer to objects that belong to concrete
subclasses of the abstract class.
Abstract Class Features
Abstract Classes Compared to Interfaces
Abstract classes are similar to interfaces. You cannot instantiate them, and
they may contain a mix of methods declared with or without an
implementation. However, with abstract classes, you can declare fields
that are not static and final, and define public, protected, and private
concrete methods. With interfaces, all fields are automatically public,
static, and final, and all methods that you declare or define (as default
methods) are public. In addition, you can extend only one class, whether
or not it is abstract, whereas you can implement any number of interfaces.
Abstract Class vs Interfaces
Which should you use, abstract classes or interfaces?
Consider using abstract classes if any of these statements apply to your
situation:
You want to share code among several closely related classes.
You expect that classes that extend your abstract class have many common
methods or fields, or require access modifiers other than public (such as
protected and private).
You want to declare non-static or non-final fields. This enables you to define
methods that can access and modify the state of the object to which they belong.
Consider using interfaces if any of these statements apply to your situation:
You expect that unrelated classes would implement your interface. For example,
the interfaces Comparable and Cloneable are implemented by many unrelated
classes.
You want to specify the behavior of a particular data type, but not concerned
about who implements its behavior.
You want to take advantage of multiple inheritance of type.
AbstractMap
HashMap
TreeMap
ConcurrentHashMap
HashMap which implements the interfaces Serializable, Cloneable,
Example-
Thank You

OOPS_AbstractClasses_explained__java.ppt

  • 1.
  • 2.
    ● This moduleintroduces patcipants to the Abstract Classes ● Describes memory allocation to Subclass objects . ● Difference between Abstract Classes and Interfaces. Module Overview 2
  • 3.
    Objectives •Able to createprograms that has better utilization of Memory. •Participant should be able to create programs that occupiest less memory and better performance. •Understanding allocation of memory to all units of the program.
  • 4.
    Abstract Classes An abstractclass is a class that is declared abstract and cannot be instantiated but can be subclassed. An abstract method is a method that is declared without an implementation . Why Abstract Class? An abstract class exists only to express the common properties of all its subclasses. A class that is not abstract is said to be concrete. You can create objects belonging to a concrete class, but not to an abstract class. A variable whose type is given by an abstract class can only refer to objects that belong to concrete subclasses of the abstract class.
  • 5.
    Abstract Class Features AbstractClasses Compared to Interfaces Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and final, and all methods that you declare or define (as default methods) are public. In addition, you can extend only one class, whether or not it is abstract, whereas you can implement any number of interfaces.
  • 6.
    Abstract Class vsInterfaces Which should you use, abstract classes or interfaces? Consider using abstract classes if any of these statements apply to your situation: You want to share code among several closely related classes. You expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private). You want to declare non-static or non-final fields. This enables you to define methods that can access and modify the state of the object to which they belong. Consider using interfaces if any of these statements apply to your situation: You expect that unrelated classes would implement your interface. For example, the interfaces Comparable and Cloneable are implemented by many unrelated classes. You want to specify the behavior of a particular data type, but not concerned about who implements its behavior. You want to take advantage of multiple inheritance of type.
  • 7.
  • 8.
  • 9.

Editor's Notes

  • #2 Instructor Notes: