Why it has to be 'void' inside the class. And why we have to use (.) between the test and sayHi | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why it has to be 'void' inside the class. And why we have to use (.) between the test and sayHi

20th Oct 2016, 1:07 AM
Seinsora x
Seinsora x - avatar
2 Answers
+ 3
Void for what? The functions? They don't have to be. Functions inside a class can have what ever return type you want. We use the dot to show what the class of the member we want to access is. If I had class A, and class B, both having a "sayHi" function, then how would my program know which function I wanted to call? Through the use of an object, I can call the sayHi function for the B class. Similarly, I can create another object for the A class to access that class' sayHi function. B bobj; A aobj; bobj.sayHi(); aobj.sayHi();
20th Oct 2016, 1:36 AM
Cohen Creber
Cohen Creber - avatar
+ 2
Thank you.. It helped me a lot
20th Oct 2016, 1:44 AM
Seinsora x
Seinsora x - avatar