Programming in Java
Inheritance
Abstract Class
Interfaces
Access Modifiers
Polymorphism
, Abstract Classes
• Abstract Class is a class whose name is preceeded
with an abstract keyword
• An abstract class must have at least one method
declared abstract.
• It may contain data members too.
• An abstract class is extended just like a concrete class.
• Any class that extends an abstract class must
fully implementation the abstract method.
• An abstract class cannot be used to Instantiate other objects
• So an abstract class is used only for the purpose of inheritance.
, Abstract Class
• For example
• The MotorVehicle class may have an abstract methods
public abstract class MotorVehicle
{ private double speed,
maxSpeed; int numofwheels
void accToMax( ) { speed =
maxSpeed;} //Abstract methods
public abstract void
setMaxSpeed( ); public abstract
void setWheels( ); /*…*/
}
• So MotorVehicle can NOT be instantiated
(ie., can not be used to create an object.)
Inheritance
Abstract Class
Interfaces
Access Modifiers
Polymorphism
, Abstract Classes
• Abstract Class is a class whose name is preceeded
with an abstract keyword
• An abstract class must have at least one method
declared abstract.
• It may contain data members too.
• An abstract class is extended just like a concrete class.
• Any class that extends an abstract class must
fully implementation the abstract method.
• An abstract class cannot be used to Instantiate other objects
• So an abstract class is used only for the purpose of inheritance.
, Abstract Class
• For example
• The MotorVehicle class may have an abstract methods
public abstract class MotorVehicle
{ private double speed,
maxSpeed; int numofwheels
void accToMax( ) { speed =
maxSpeed;} //Abstract methods
public abstract void
setMaxSpeed( ); public abstract
void setWheels( ); /*…*/
}
• So MotorVehicle can NOT be instantiated
(ie., can not be used to create an object.)