Inheritance

This commit is contained in:
2024-09-18 20:28:26 +02:00
parent 9534ee8156
commit 4908d26105
10 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package com.oop;
public class Car extends Vehicle {
Car(){
inheritedName = "HERITAGE!";
}
}

View File

@ -8,5 +8,18 @@ public class Main {
Pupil pupil = new Pupil();
pupil.setAge(a);
Standard standard1 = new Standard();
Pro pro1 = new Pro();
//standard version
standard1.draw();
standard1.write();
//Pro version
pro1.draw();
pro1.write();
pro1.useEffects();
pro1.changeResolution();
}
}

View File

@ -0,0 +1,11 @@
package com.oop;
public class Pro extends Standard {
protected void useEffects() {
System.out.println("Using Effects");
}
protected void changeResolution() {
System.out.println("Changing Resolution");
}
}

View File

@ -0,0 +1,11 @@
package com.oop;
public class Standard {
protected void draw() {
System.out.println("Drawing");
}
protected void write() {
System.out.println("Writing");
}
}

View File

@ -0,0 +1,31 @@
package com.oop;
public class Vehicle {
protected String inheritedName;
static int counter;
public int maxSpeed;
public int wheels;
public String color;
public double fuelCapacity;
public Vehicle() {
this.setColor("Red");
}
Vehicle(String c) {
this.setColor(c);
}
public void horn() {
System.out.println("Beep!");
}
//Getter
public String getColor() {
return color;
}
// Setter
public void setColor(String c) {
this.color = c;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.