ECM1406: Data Structures and Team Project Inheritance and Exception Handling Inheritance and Exception Handling 1/16
ECM1406: Data Structures and Team Project
Inheritance and Exception Handling
Inheritance and Exception Handling 1/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
Represents a “is-a” relationship.
Single inheritanceSubclass derived from one existing class (superclass)
Multiple inheritanceSubclass derived from more than one superclass
Not supported by Javaa class can only extend the definition of one class.
Inheritance Inheritance and Exception Handling 2/16
Inheritance
〈modifer(s)〉 class SubClass extends SuperClass 〈modifier(s)〉 {
classMembers}
Inheritance Inheritance and Exception Handling 3/16
Inheritance
〈modifer(s)〉 class SubClass extends SuperClass 〈modifier(s)〉 {
classMembers}
Inheritance Inheritance and Exception Handling 3/16
Inheritance
〈modifer(s)〉 class SubClass extends SuperClass 〈modifier(s)〉 {
classMembers}
Inheritance Inheritance and Exception Handling 3/16
Inheritance
〈modifer(s)〉 class SubClass extends SuperClass 〈modifier(s)〉 {
classMembers}
Inheritance Inheritance and Exception Handling 3/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier:
super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier: super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier: super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier: super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using:
super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier: super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using: super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
Inheritance
Access to superclass’ membersprivate: a subclass can not access a superclass’ private members.
protected: it can however, access a superclass’ protected members.
Overriding
A subclass can override a method in the superclass.The redefinition only applies to objects of the subclass.The subclass can still access the superclass’s method usingthe super class specifier: super.method(. . .)
Constructor
The subclass’ constructor can call the superclass’constructor using: super(. . .)
Must be the first statement in the subclasses constructor.
Inheritance Inheritance and Exception Handling 4/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
The Object Class
All classes inherit from the Object superclass.Public member can be overridden/invoked by an object ofany class.
public Object()
Constructorpublic String toString()
Method to return a string to describe the objectpublic boolean equals(Object obj)
True when current object and obj are the same instance.protected Object clone()
Returns a reference to a copy of the Object.protected void finalize()
Invoked when the object goes out of scope.
The Object Class Inheritance and Exception Handling 5/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Objects of Superclasses and Subclasses
Automatic CastingReference to a subclass can not refer to a superclass object.Reference to a superclass can refer to its subclass objects.
Class Cast ExceptionOccurs if the class cast is not allowed.Casting up the inheritance tree is not allowed.Casting down the tree is.
Dynamic BindingMethod executed determined at execution time, notcompile time.
instanceof
Determines whether reference variable that points toobject is of particular class type.if ( object instanceof Class ) . . .
The Object Class Inheritance and Exception Handling 6/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Abstract Methods and Classes
Abstract Method
A method that has only the heading with no body.Must be declared abstract.A subclass must defined the method.
Abstract Class
Class that is declared using the abstract modifier.Cannot have an instance of abstract class type.Can refer to an abstract class (a reference variable).Can instantiate object of subclass of abstract class.Subclass must give definition of all abstract methods.
Composition
Class members are objects of another class type.Represents a “has-a” relationship between classes.
Abstraction Inheritance and Exception Handling 7/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
Exceptions
An occurrence of an undesirable situation that can be detectedduring program execution.
ExamplesDivision by zero.An array index that goes out of bounds.Trying to open an input file that does not exist.
Exceptions Inheritance and Exception Handling 8/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Throwable Class
public Throwable()
Default constructor: no message.public Throwable(String msg)
Constructor: set message to msg.public String getMessage()
Return the objects message.public void printStackTrace()
Print a stack trace showing the sequence of method callswhen the exception occurred.public void printStackTrace(PrintStream stream)
public void printStackTrace(PrintWriter stream)
As printStackTrace() but sends output to stream.public String toString()
Returns a string representing the Throwable object.
Exceptions Inheritance and Exception Handling 9/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
The Exception Class
Subclass of class ThrowableSuperclass of classes designed to handle exceptions.
Various types of exceptionsI/O exceptionsNumber format exceptionsArray index out of bounds exceptionFile not found exceptions
Exception CategoriesThe different exception categories are separate classes andcontained in various packages.
The Exception Classpublic Exception()
public Exception(String msg)
Constructors inherited from Throwable.Exceptions Inheritance and Exception Handling 10/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Some Exception Classes
ArithmeticException An arithmetic error, such as division by zero.
ArrayIndexOutOfBoundsExceptionArray index < 0 or > array length.
FileNotFoundException Referencing a file that cannot be found.
IllegalArgumentExceptionCalling a method with illegal arguments.
IndexOutOfBoundsExceptionAn array index is out of bounds.
NullPointerException Reference an object which has not beeninstantiated.
NumberFormatException Use of an illegal number format.
StringIndexOutOfBoundsExceptionString index < 0 or > length of string.
Exceptions Inheritance and Exception Handling 11/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Exceptions Thrown by Methods
NumberFormatExceptionparseInt(String str) str does not contain a valid int.parseDouble(String str) str does not contain a valid double.valueOf(String str) str does not contain a valid value.
NullPointerExceptionString(String str) str is null.indexOf(String str) str is null.lastIndexOf(String str) str is null.
StringIndexOutOfBoundsException
charAt(int a) a is not a valid index.substring(int a) a is not a valid index.substring(int a, int b) a and/or b is not a valid index.
Exceptions Inheritance and Exception Handling 12/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Checked Exceptions
Checked ExceptionAny exception that can be analysed by the compiler.Example: IOExceptions
Unchecked ExceptionsException that cannot be analysed when the program iscompiled.Must be checked for by programmer.Example: Division by zero.Example: Array index out of bounds.
Syntaxthrows 〈Exception1〉, 〈Exception2〉Attach modifier between the class/method declarationand the definition body.
Exceptions Inheritance and Exception Handling 13/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling
try blockIncludes statements that may generate an exception.Includes statements that should not be executed if anexception occurs.Followed by zero or more catch blocks.
catch blockSpecifies type of exception it can catch.One catch bock for each type of exception.Can catch a specific exception or a category of exceptions.Contains the complete exception handler.Order of catch blocks is important – later blocks ignored.
finally blockCode is always executed whether exception occurs or not.Optional, except when no catch blocks are present.
Exception Handling Inheritance and Exception Handling 14/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Exception Handling Techniques
Terminate programOutput an appropriate error message and terminate.
Fix error and continueGenerate an appropriate error message, wait for userinput and try again (repeatedly until a valid input isobtained).
Log error and continueWrite error messages (to a logfile) and continue withprogram execution.
RethrowIf unable to process the exception.If exception should be handled by calling environment.Default action if exception is not caught.
Exception Handling Inheritance and Exception Handling 15/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16
Creating Your Own Exception Classes
Allows the class to provide additional information to thecaller as to the cause of the exception.
Caller can analyse the additional information and respondaccordingly.
Exception Definition
Extend the Exception class or one of its subclassespublic class NodeNotFoundException extends Exception {
public NodeNotFoundException() {super("NodeNotFoundExcpetion");
}}
Throwing an Exception
The syntax to throw your own exception is:throw new NodeNotFoundException();
Custom Exceptions Inheritance and Exception Handling 16/16