Object-Oriented Programming
Classes
Classes are the blueprint of objects. Now you will think about what actually blueprints are. Blueprints are actually a design or plan to build something. Let's take an example like the map is detail plan of house classes are detail plan in Object-Oriented programming. let's give you an example of a class on java so that you can unferstand.
public class Car {
int horsePower;
String name;
String color;
String Company;
}
public class Sample {
public static void main(String[] args) {
Car car;
Car mehran;
}
}
Class name always start with capital letters . It is a good practice to name classes . We will later learn how this is good. So in the above class Car is the name of the class and horsePower , name and color are properties of class, Which we can have any of any car. If you see the main of your program you can see that a variable of type car is created with name car and only way we can differentiate between type and variable name here is that type is starting with capital letter so now you got why we start class name with capital letter . In the above code Car is the type which we created and car, mehran are it's objects. Objects are what objects are those instance which we created using blueprint ( class) and we create n number of instances from our classes. So know we will learn about access modifier and member functions in upcoming tutorials.
Comments
Post a Comment