0

What are objects in programming?

As 'method' is said to be like a function, but applied on objects. What are the objects?

8th Jan 2020, 4:39 AM
Sudheer Yerra
Sudheer Yerra - avatar
3 Respuestas
+ 2
Sudheer Yerra Any class has some functionality and methods included in the class. But to access that class property an run time entity is required which is used to access any of the properties so that run time entity is object. for example look on below snippet. class aClass { public: aClass(int value1) { member = value1; } void SetMember(int value) { member = value; } int member; }; void testFunc(MyClass& obj) { // How to define the parameter obj so that: obj.SetMember(2); // Modifying the object is allowed obj = MyClass(123); // But replacing the object like this is not. } int main() { MyClass obj1(1); cout<<"obj1.member: "<<obj1.member<<std::endl; testFunc(obj1); cout<<"obj1.member: "<<obj1.member<<std::endl; return 0; }
8th Jan 2020, 4:46 AM
MsJ
MsJ - avatar
+ 1
Sudheer Yerra, for now maybe best to stick to what you have already seen in the tutorial. Let's take Python's type 'list'. You can create all sorts of list with different contents. Each one of them is an object, and shares the methods of the type list. One of the methods is 'append' - it allows you to put a new item into your list at the end. a = [1, 2, 3] b = ['a', 'b', 'c'] a.append('d') b.append(4) So both lists can use the method append, and it will only change that one list you specified in the beginning (the object). So a and b now look like this: [1, 2, 3, 'd'] ['a', 'b', 'c', 4]
8th Jan 2020, 9:48 AM
HonFu
HonFu - avatar
0
This is in C++ but see if it help https://www.sololearn.com/discuss/2075135/?ref=app
8th Jan 2020, 5:17 AM
Avinesh
Avinesh - avatar