Abstract

Description:

Abstract class: abstract classes cannot be instantiated, you have to inherit it from another class, and provide implementations to the abstract methods in it.

Abstract method: A method that exist that has no implementation, must be defined in subclasses

overloading: feature that allows a classes to have functions with the same name as long as the parameters differ.

When to useUse abstract classes for when you only want to instantiate an object of it as a subclass 

Exmaple:

Abstract Class:

public abstract class Pokemon {
    
public abstract void attack();
  
 public abstract void attack(String tm);
}

Sub Class:

public class Charmander extends Pokemon{
  
 public void attack() {
        System.
out.println("Used flamethrower");    
    }
    
public void attack(String tm) {
        System.
out.println("Used " + tm);
    }
}

Sub Class:

public class Squirtle extends Pokemon{
    
public void attack() {
        System.
out.println("Used water gun");
    }
    
public void attack(String tm) {
        System.
out.println("Used " + tm);
    }
}

Main class:

public class Main {
  
 public static void main(String[] args) {
        Pokemon
charchar = new Charmander();
        Pokemon
squirt = new Squirtle();
        
        Pokemon[]
pokemon = new Pokemon[2];

        pokemon[0] = charchar;
        
pokemon[1] = squirt;
        
        
for(int i = 0; i < pokemon.length; i++){
            
pokemon[i].attack();
            
pokemon[i].attack("cut");
        }
    }
}

Results:

Used flamethrower
Used cut
Used water gun
Used cut

Challenge Problem