0
What is object? And how to initialize an object?
2 Answers
+ 4
An object is an instance of a class.
For example, if this was your class..
class Apple
{
// your code here
// default constructor is used
// unless you write your own
};
This is how you'd make an object of it:
Apple variable_name = new Apple();
You now have an object of Apple, called variable_name.
0
An object basically has attributes and methods.
An object is created from a class using a constructor.
For example I may have a class called Vehicle which might have the attributes make, manufacturer and horsepower.
To create an object from the Vehicle class i would do something similar to Vehicle car1 = new Vehicle();