Question:
(a) (i) Explain how class members can be accessed when using objects of the class. Use a suitable example to illustrate your answer.
(ii) Explain how the private data members of a class can be accessed using suitable example of your own.
(b) Distinguish between the different types of access modifiers and explain clearly their use in programs.
(c) (i) Explain how objects can be created and initialized at the same time using a suitable example of your own.
(ii) What is the maximum number of constructors which can be defined in a class? Explain clearly.
(d) Write down the class 'Rectangle' to contain the following:-
(i) attributes length and width
(ii) a no-argument constructor to initialize both the length and width to 1.
(iii) an overloaded constructor to initialize the length and width to values entered by the user
(iv) set and get methods for both the length and width
(v) methods to calculate the perimeter and area of the rectangle object