Skip to content

Commit

Permalink
Inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
KatsuMouley committed May 10, 2024
1 parent 39add6c commit 3b13318
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Objects/Bicycle.java
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
package Objects;
public class Bicycle extends Vehicle {
public String Typename = "Bike";
public int wheels = 2, pedals = 2;
}
3 changes: 2 additions & 1 deletion src/Objects/Car.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package Objects;

public class Car extends Vehicle {
public String name;
public String name, Typename = "Car";
public String make = "Chevrolet";
public String model = "Corvette";
public int year = 2020;
public String color = "blue";
public double price = 50000.00;
public int wheels = 4, door = 4;

public Car(){}
public Car(String name){
Expand Down
14 changes: 14 additions & 0 deletions src/Objects/Friend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Objects;

public class Friend {


public String name;

public static int numberOfFriends;

public Friend(String name){
this.name=name;
numberOfFriends++;
}
}
13 changes: 12 additions & 1 deletion src/Objects/Vehicle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package Objects;

public class Vehicle {

// inheritance = the process where one class acquires,
// the attributes and methods of another.
public String Typename;
public double speed;

public void go(String Typename){
System.out.println("The "+Typename+" is moving");
}
public void stop(String Typename){
System.out.println("The "+Typename+" is stopped");
}

}
22 changes: 22 additions & 0 deletions src/files/Inheritance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package files;
import Objects.Bicycle;
import Objects.Car;

public class Inheritance {
public static void main(String[] args) {
run();
}
public static void run() {Car car = new Car();

car.go(car.Typename);
car.stop(car.Typename);

Bicycle bike = new Bicycle();

bike.go(bike.Typename);
bike.stop(bike.Typename);

System.out.println(car.door);
System.out.println(bike.pedals);
}
}
20 changes: 20 additions & 0 deletions src/files/StaticKeyWord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package files;

import Objects.Friend;

public class StaticKeyWord {
// static = modifier. A single copy of a variable/method is created and shared.
// The class "owns" the static member

public static void main(String[] args) {
run();
}
public static void run() {
//Static key world can be used in function oriented programing. Usually it's not so used in OOP
Friend friend1 = new Friend("Sponegbob");
Friend friend2 = new Friend("Patrick");
Friend friend3 = new Friend("Patrick");

System.out.println(Friend.numberOfFriends);
}
}
5 changes: 0 additions & 5 deletions src/files/_Inheritance.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/files/_StaticKeyWord.java

This file was deleted.

0 comments on commit 3b13318

Please sign in to comment.