Mostenirea – Inheritance

//fisierul Masina.java

public class Masina {
     
    protected String nume = "Masina Tipul 1";
     
    public void start() {
        System.out.println("Masina porneste.");
    }
     
    public void stop() {
        System.out.println("Masina se opreste.");
    }

    public void stergeParbrizul() {
			
	}

	 public void arataInfo() {
		
	}

	
}

public class Masina {
     
    protected String nume = "Masina Tipul 1";
     
    public void start() {
        System.out.println("Masina porneste.");
    }
     
    public void stop() {
        System.out.println("Masina se opreste.");
    }

    public void stergeParbrizul() {
			
	}

	 public void arataInfo() {
		
	}

	
}
//fisierul Vehicul.java

public class Vehicul extends Masina {
     
     
    @Override
    public void start() {
        System.out.println("Masina porneste");
    }
 
    public void stergeParbrizul() {
        System.out.println("Sterge parbrizului");
    }
     
    public void  aratanfo() {
        System.out.println("Masina nume: " + nume);
    }
}
//fisierul App.java

public class App {
 
    public static void main(String[] args) {
        Masina masi1 = new Masina();
         
        masi1.start();
        masi1.stop();
        
        masi1.start();
        masi1.stergeParbrizul();
        masi1.arataInfo();
        masi1.stop();
         
         
    }

}
Output is:
Masina porneste.
Masina se opreste.
Masina porneste.
Masina se opreste.