object oriented development code example
Example 1: object-oriented programming
class Person {
void walk() {
System.out.println(“Can Run….”);
}
}
class Employee extends Person {
void walk() {
System.out.println(“Running Fast…”);
}
public static void main(String arg[]) {
Person p = new Employee();
p.walk();
}
}
Example 2: object oriented programming
public class Car
{
private double speed;
public Car(double initialSpeed)
{
speed = initialSpeed;
}
public double getSpeed()
{
return speed;
}
public void accelerate()
{
speed++;
}
public void slowDown()
{
speed--;
}
}