Quote: "I hate oop and will never learn it."
The world is built up of objects, like Vehicles.
Objects have attributes (properties).
class Vehicle
{
int milesDriven;
int amountOfFuel;
}
Objects can do things, just like in the real world.
class Vehicle
{
int milesDriven;
int amountOfFuel;
driveForward( int miles )
{
amountOfFuel -= miles/10;
milesDriven += miles;
}
}
Objects need a way to be created
class Vehicle
{
int milesDriven;
int amountOfFuel;
Vehicle( int fuel )
{
milesDriven = 0;
amountOfFuel = fuel;
}
driveForward( int miles )
{
amountOfFuel -= miles/10;
milesDriven += miles;
}
}
And then they can be created:
Vehicle test = new Vehicle( 100 );
test.driveForward( 10 );
Objects can also be types of other objects
class Car extends Vehicle
{
addFuel( int fuel )
{
amountOfFuel += fuel;
}
}
And they can also be built like their parents
Car test2 = new Car( 100 );
test2.driveForward( 10 );
test2.addFuel( 1 );
Objects can also contain other objects
class Color
{
int red;
int green;
int blue;
Color( int r, int g, int b )
{
red = r;
green = g;
blue = b;
}
}
class Car extends Vehicle
{
Color c;
addFuel( int fuel )
{
amountOfFuel += fuel;
}
setColor( int r, int g, int b )
{
c = new Color( r, g, b );
}
}
Car my_car = new Car( 150 );
my_car.setColor( 255, 0, 100 );
my_car.driveForward( 50 );
And that is the basics of OOP!