+ 1

What is object and class in programming language?

5th Aug 2016, 3:13 AM
CH.Durga Prasanna Kumar
CH.Durga Prasanna Kumar - avatar
3 Answers
+ 3
think of a class as a set of guide lines for what the object is and can be or do.
5th Aug 2016, 11:52 AM
Logan Kirkendoll
Logan Kirkendoll - avatar
+ 3
Think of it as a Class being like a blueprint for an object. In a Class you define the properties (members) and behaviours (methods) the object can have or can do. The object is what you will construct from the Class which will then have the properties you can configure and actions it can perform. Example: class Car { // Properties public int NumberOfDoors {get; set;} public string Manufacturer {get; set;} // Methods public void Drive() { // Code to describe what happens when a car drives. } // Constructor public Car(int wheels, string manufacturer) { // Describes how to build your object. this.Wheels = wheels; this.Manufacturer = manufacturer; } You can then use this as follows: public static Main(string[] args) { // Build (instantiate) your car (object) from your car blueprint (class) using the constructor. Car myCar = new Car(7, "Mercedes"); // Tell your car object to drive. myCar.Drive(); } (Who wouldn't want a seven wheeled Mercedes right?) The principle being you can create multiple variations of the object from a single blueprint.
5th Aug 2016, 2:01 PM
Laurence Turner
Laurence Turner - avatar
+ 2
A class is a template for an object, while an object itself is an instance of a class. Think of a class as a Bank Account for example. let's have a deposit variable and an interest_rate variable in our BankAccount class. To create an object we can create an instance/copy of the type BankAccount. Assume we create 2 copies, and give them a reference of john and mary. john object will have its own deposit variable and interest_rate variable and so will mary. none of the object variables influences the value of another. The main reason for OOP according to me though is creating a sense of order in your code. it organizes your code in a manageable way that will allow you edit your code with ease. This will be evident when dealing with huge projects.
5th Aug 2016, 4:28 AM
Nick Nderitu
Nick Nderitu - avatar