Week 6 T+L 8 Object-Oriented Programming
Week 6 T+L 8 Object-Oriented Programming
time polymorphism)
class Vehicle {
void travel() {
System.out.println("The vehicle is
traveling...");
@Override
class Car {
void travel() {
} }
return travels;
Week 6 T+L 8
Object-Oriented Topics 1.OOP Principles 2. Encapsulation 3. Inheritance 4. Polymorphism 5. Method Overloading 6. Constructor Overloading
Programming
Bundling of data (attributes) class Vehicle { class Vehicle {
Establishing a relationship
System.out.println("The vehicle is
between classes, where one } traveling...");
Inheritance: class (child) inherits properties
The four main principles of and behaviors from another } }
Example
public static void main(String[] args) { System.out.println("The vehicle is
traveling by " + mode + " at a speed of " +
speed + " km/h.");
Vehicle myVehicle = new Vehicle();
}
myCar.travel(); // Calls Car's overridden travel method public static void main(String[] args) {
myVehicle.travel("road"); // One
argument