Object Oriented Programming - Classes & Objects
Object Oriented Programming Including Classes & Objects
Shane Walsh - 06/12/22 - G00406694@atu.ie
What is Object Oriented Programming?
Object oriented programming (OOP) is a concept that allows the users to create various objects they want and create methods to handle those objects. The basic concept is pretty much just the creation of objects that can be re-used throughout a program to do math, produce a sentence or possibly manipulate data.
OOP involves the principles of Abstraction, Encapsulation, Inheritance and even Polymorphism. But those are not necessary to dive deep into at this current time. For now we will cover the two most crucial spaces of Object Oriented Programming Classes and Objects.
Classes:
Classes are like groups of similar things. It's mostly a logical component and not really a physical entity. An example would be things like Cars, Animals or Houses. These classes could then have associated objects like BMW, Tiger or Bungalow. Data created and used within these example classes could be things such as the price of a car, max speed, speed of an animal or square foot of a house.
Objects:
Objects can be thought of as like an instance of a class, there can be many of these within a class instantiated within a program. Objects can contain both data and functions (known as Methods in java) which change or alter the data present. These objects could be things like a table object within a furniture class, with data such as wood type or amount that can be seated.
Variables:
There are various types of containers or variables we use to store data used in java programs. These variables are data types which allow the user to decide types and quantities of values held. variables are memory locations stored within your pc's program space. They can be declared as local, final and static.
Variables fall within data types, which are split into two types.
Primitive:
- Byte
- Short
- Integer
- Long
- Char
- Float
- Double
- Boolean
Non-primitive:
Strings are technically array data types. Essentially a collection of characters. While the deeper roots of how this all works can be explored down the road, for now we will use them with this base knowledge in mind as it's not appropriate to leave what makes up such a crucial element of our life logic for later when you cover arrays.
Variables are declared like below, with the type first and then your chosen name for your variables:
Data is initialized into variables by assigning a value to the reference name of the variable. Such as: count = 10;
dog = "woof";
price = 2.99
grade = 5.4
With all these variables you are now free to perform various types of math using the data we've created storage points for. See below an example of various variables being assigned, initialized and used to perform different math equations and outputted accordingly in println methods using String variables.
References:
https://www.oracle.com
https://www.w3schools.com/java/default.asp
Comments
Post a Comment