Object Oriented Programing - What is a Class?
A Class can be thought of as the blueprint of an Object.
Think about a house blueprint. You can't live in it, but you can build a house from it, which means you build an instance of it. An Object is an instance of a Class.
So what exactly is a class? it is a bunch of code that can contain methods, variables, loops, and all other types of code syntax.
[box type="info" align="" class="" width=""]As a convention Class names should be Proper cased and Camel cased[/box]
The following code defines a 'Car' class

from the above classes we can create many types of Car object from the 'Car' Class and define different characteristics for each.
we could do the following to Create an Object from our Defined Class.
Now we know that all Cars should at least posses the ability to be accelerate which leads us to Functions (or Methods)

[box type="shadow" align="" class="" width=""]
Further Reading:
https://en.wikipedia.org/wiki/Class_(computer_programming)
Think about a house blueprint. You can't live in it, but you can build a house from it, which means you build an instance of it. An Object is an instance of a Class.
So what exactly is a class? it is a bunch of code that can contain methods, variables, loops, and all other types of code syntax.
[box type="info" align="" class="" width=""]As a convention Class names should be Proper cased and Camel cased[/box]
The following code defines a 'Car' class
// Java Code class Car{ private String name; // member variable private String color;// member variable private int topSpeed;// member variable //Constructor of a Class public Car(String name, String color, int topSpeed) { this.name = name; this.color = color; this.topSpeed = topSpeed; } /* In object-oriented programming, a Constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables. */ }
// Kotlin Code. You Should learn Kotlin! it's concise class Car(val name: String, val color: String, val topSpeed: Int)

from the above classes we can create many types of Car object from the 'Car' Class and define different characteristics for each.
we could do the following to Create an Object from our Defined Class.
//in java Car car1 = new Car ("polo", "Green", 200); Car car2 = new Car ("mini", "Blue", 185); Car car3 = new Car ("beetle", "Red", 165);
val car1 = Car ("polo", "Green", 200) val car2 = Car ("mini", "Blue", 185) val car3 = Car ("beetle", "Red", 165)car1, car2, car3 are our objects from'Car' class.
Now we know that all Cars should at least posses the ability to be accelerate which leads us to Functions (or Methods)

[box type="shadow" align="" class="" width=""]
Further Reading:
https://en.wikipedia.org/wiki/Class_(computer_programming)
Comments
Post a Comment