What is object? And how to initialize an object? | Sololearn: Learn to code for FREE!
0

What is object? And how to initialize an object?

26th Mar 2017, 11:04 PM
Benjamin Chauka
Benjamin Chauka - avatar
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.
31st Mar 2017, 10:53 PM
Neen
Neen - avatar
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();
27th Mar 2017, 12:40 AM
Hassie
Hassie - avatar