That's because these methods will accept some values from the user to calculate the area and volume of the shape
Why would your area and volume methods accept values from user?
Okay all the child classes has a getter and setter for user input
The user will provide some input, the area and Volume will use this input to calculate the area and volume
What exactly does getters and setters do? As per my knowledge getters returns the value of class members And setters set the value of class members
Getters get the member variables, setters set the member variables. It's just a name for methods which do these
Yeah and for calculating the area and Volume I need to pass these members
Again why would you want to pass these parameters to area and volume? member functions (methods) already have access to members variables
class A { // member variables double my_member_variable_of_A; // method (member functions) void fun() { my_member_variable_of_a = 5.0; // see you can access them here } double another_method() { return my_member_variable_of_a; } }
Ohh okay if a method is defined within class scope it doesn't need to have parameters for accessing the members variables got it
That is a weird way if phrasing it but, yeah. A class's methods can access it's member variables and even other methods it has.
Btw @Dabjazz the another_method() is a getter for my_member_variable_of_a It is not a good coding practice to have these weird names for getters though.
Обсуждают сегодня