OOP - Objects: Fields and Methods

What is Object Oriented Programming.
Is about programming modelling around objects.
We will be using Java for this OOP tutorials.

An object is an enhanced data type; that has fields and methods kind of like a primitive type ie int x


Objects:
-Combine variables together to make your code more meaningful
-Code becomes organised and easier to understand
-Code becomes more easier to maintain.
_________________________________________

For example for a car

For Fields:
-String make
-String model
-int year

To access or write the car year:
We would use: car.year

int myCarYear = car.year;
Sytem.out.println(car.year);
car.year = 2007;

Methods:In other words they are running actions that kind of look like calling a function)
Methods like any functions can take arguements.

void openDoor(int doorNo)

If you wanted to open the back door. you could do the following

openDoor(5). Assuming the back door is 5.

Objects are only really useful when we use fields and methods together.
Sometimes objects might just use methods or might just use fields.

Comments

Popular posts from this blog

Java Basics - Variable and Data Types Part 1

Java Basics - Variable and Data Types Part 2

OOP - Objects and Classes