Defining a Template for Classes to Extend - Java Object Oriented Design

Java examples for Object Oriented Design:Abstract Class

Introduction

Define an abstract class with fields and functionality that can be used in other classes.

The abstract class can include unimplemented methods, known as abstract methods.

The abstract methods will need to be implemented by a subclass of the abstract class.

Demo Code

abstract class Schedule {
    /*from w ww  . j ava 2s  .  com*/
    public String scheduleYear;
    public String teamName;
    
    
    public Schedule(){}
    
    public Schedule(String teamName){
        this.teamName = teamName;
    }
    
    abstract void calculateDaysPlayed(int month);
    
}
 class TeamSchedule extends Schedule {

   public TeamSchedule(String teamName) {
       super(teamName);
   }

   @Override
   void calculateDaysPlayed(int month) {
       int totalGamesPlayedInMonth = 0;

       System.out.println("Games played in specified month: " + totalGamesPlayedInMonth);
   }

}

Related Tutorials