-4

If I say car as an example of class. Then what should be the object then?

I know their are many other simpler examples but it would be helpful to know object for this particular example.

class car{

    char name[100];
    ..  
}

Object_type ob = new Object_type

What should be the object here?

SiHa
  • 7,830
  • 13
  • 34
  • 43
yureka
  • 89
  • 8
  • 1
    ob is object of class car.when ob is created it can access member function and member variable.you can access with help of dot(.) operator. – The developer Oct 05 '16 at 11:54
  • 5
    Most [good beginners books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) discuss the difference between a class and an object. As do lots (and I mean ***lots***) of OOP tutorial sites. – Some programmer dude Oct 05 '16 at 11:54

2 Answers2

0

If you are creating a Car class, then objects would be instances of Cars. For example different models and types of car:

Car alpharomeo;
Car audi;
Hennio
  • 433
  • 2
  • 18
0

Here is the syntax that you want:

class car { // define the class 'car'
    char name[100];
    };


car * myCar = new car();    // declare the object 'myCar'

in this case 'car' is the class, and 'myCar' is an object of that class.

Gregg
  • 2,444
  • 1
  • 12
  • 21
  • actually for an interview i was asked to give a real time example for classes and objects, for which i said car. Then the next question was then what will be the object. for which i replied different manufacutes like audi,figo... – yureka Oct 05 '16 at 12:46
  • and the interviewer was not satisfied with the object answer which i said ...can you give me a better choice of answer – yureka Oct 05 '16 at 12:47
  • 1
    He may have been looking for the answer than an object is an actual particular car (sitting is some one's driveway). But as far as the compiler is concerned, an object exists if the run time code allocates space and has code linked in for it (if defined). – Gregg Oct 05 '16 at 12:50
  • A better answer would be that if the car is a class, the objects are the ones parked outside. – UKMonkey Oct 05 '16 at 13:24