Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the term used to indicate the variable and constants of a class?(a) Data members(b) Variables of class(c) Data characters(d) ConstantsI had been asked this question during a job interview.My query is from Data Members topic in portion Class Members & Types of Object Oriented Programming

Answer»

Right answer is (a) Data members

The best explanation: The variables inside a class are termed data members of the class. It is not a mandatory RULE but variables are USED to refer to usual variables used in functions or globally. The term is given because the VALUES stored in those variables represent some KIND of data related to class.

2.

Data members ________________ (C++)(a) Can be initialized with declaration in classes(b) Can be initialized only with help of constructors(c) Can be initialized either in declaration or by constructor(d) Can’t be initializedI had been asked this question in an internship interview.The origin of the question is Data Members topic in section Class Members & Types of Object Oriented Programming

Answer»

The CORRECT choice is (b) Can be initialized only with help of constructors

The EXPLANATION: The data members are not property of class, those are property of the instances of the class. And the memory for the data members are not RESERVED until a CONSTRUCTOR is called. HENCE we use constructors for their initialization after the memory is reserved.

3.

Which among the following is true for data members?(a) Private data members can be initialized with declaration in class(b) Static members are initialized in constructors(c) Protected data members can be initialized in class directly(d) Static data members are defined outside class, not in constructorThis question was posed to me in an interview for job.My doubt stems from Data Members topic in division Class Members & Types of Object Oriented Programming

Answer»

The CORRECT choice is (d) Static data MEMBERS are DEFINED outside class, not in constructor

The best explanation: Static members are not property of instances of classes. Those are shared by all the object of classes. HENCE those are defined outside the constructor, so as to make them COMMON for all the objects.

4.

What should be done for data member to be of user defined structure type?(a) The structure must have been defined before class.(b) The structure must have been defined after the class definition(c) The structure must be predefined(d) The structure type data members can’t be usedThe question was posed to me in semester exam.My question is from Data Members topic in division Class Members & Types of Object Oriented Programming

Answer»

Correct option is (a) The STRUCTURE must have been defined before class.

The EXPLANATION is: The structure must have been defined prior to its use. If the structure is not defined, then the memory space will not be allocated for its MEMBERS. This LEADS to undefined use of new data TYPES.

5.

How many data members can a class contain?(a) 27(b) 255(c) 1024(d) As many as requiredI have been asked this question during an interview.Query is from Data Members in portion Class Members & Types of Object Oriented Programming

Answer»

Right answer is (d) As many as REQUIRED

The best I can EXPLAIN: Any CLASS can have as many data members as required. The only RESTRICTION that may arise is when there is not enough memory space. This gives FLEXIBILITY to define a class with best properties possible.

6.

How to access data members of a class?(a) Dot operator(b) Arrow operator(c) Dot or arrow as required(d) Dot, arrow or direct callI had been asked this question during an interview.My question is from Data Members topic in chapter Class Members & Types of Object Oriented Programming

Answer»

Right CHOICE is (c) Dot or arrow as required

The EXPLANATION: The DATA members can never be called directly. Dot operator is USED to access the members with help of object of class. Arrow is USUALLY used if pointers are used.

7.

To create a pointer to a private data member of a class, outside the class, which among the following is correct?(a) Return the address of the private data member using a member function(b) Access the private member using a pointer outside class(c) Declare the member as pointer inside the class(d) Not possible to create pointer to a private memberI had been asked this question in an international level competition.This intriguing question originated from Data Members in section Class Members & Types of Object Oriented Programming

Answer»

The CORRECT choice is (a) Return the address of the private DATA member using a member function

The BEST explanation: We can CALL a public member function and return the address of any private data member. Though the pointer being returned must be defined INSIDE class itself. And the returned address can be stored in a pointer.

8.

Which among the following is true for use of setter() and getter() function?(a) Considered best for manipulating data values(b) Considered the only proper way to manipulate the values(c) Considered specially for private members manipulation(d) Considered a red flag, and not recommended for large scale useI have been asked this question in an international level competition.The above asked question is from Data Members topic in chapter Class Members & Types of Object Oriented Programming

Answer» CORRECT option is (d) Considered a red flag, and not recommended for large scale use

The best explanation: This CONCEPT of getter and setter functions is not acceptable if used too much. This is considered to be inappropriate in OOP perspective. Though it is commonly used, it doesn’t work according to OOP CONCEPTS at some HIGHER level of understanding.
9.

The static member functions can only use ________(a) Static data members(b) Private data members(c) Protected data members(d) Constant data membersI had been asked this question in a job interview.The query is from Data Members in portion Class Members & Types of Object Oriented Programming

Answer»

The correct answer is (a) STATIC data MEMBERS

To explain: The static member functions can only access static data members. This is because the static member function can’t WORK with the properties that change object to object. It is mandatory that only the common properties of all the objects be used. And only static data members are common to all as those are PROPERTY of class.

10.

A class can have self-referential data members.(a) True(b) FalseI have been asked this question in semester exam.The doubt is from Data Members topic in chapter Class Members & Types of Object Oriented Programming

Answer»

Right choice is (b) False

The explanation is: The DATA members in a class can never refer to own class TYPE. This is not POSSIBLE because the data members should have some memory allocated for its object before the self-reference is used, but class MUST CALL constructor for that. Hence not possible.

11.

What is the keyword used to make data members have same value?(a) static(b) const(c) double(d) abstractThe question was asked in an international level competition.Enquiry is from Data Members topic in portion Class Members & Types of Object Oriented Programming

Answer»

Right OPTION is (b) const

Easy explanation - The keyword const can be used ANYWHERE to make the VARIABLE have same value all the time. This restriction is made to use the same value whenever required. Also, this can restrict accidental changes.

12.

Which data members can be inherited but are private to a class?(a) Private(b) Protected(c) Protected and Static(d) Privately inheritedI have been asked this question in an interview.The origin of the question is Data Members in chapter Class Members & Types of Object Oriented Programming

Answer»

Correct answer is (b) Protected

To explain I WOULD say: Static MEMBERS inheritance ALSO depends on the TYPE of specifier they have. Only the protected members can be inherited but remain private to class. If static members are defined in private access, they won’t be allowed for inheritance.

13.

The arguments passed to member functions by reference are considered as data members of class.(a) True(b) FalseThe question was posed to me during an interview.This intriguing question comes from Data Members topic in section Class Members & Types of Object Oriented Programming

Answer»

The correct option is (b) False

Best explanation: This is a wrong STATEMENT. As only the data defined inside CLASS is considered as its member. But even if a variable is PASSED by reference it would be the same variable that is outside the class. HENCE it can’t be considered class member.

14.

Which among the following is not allowed for data member declaration?(a) int a;(b) static int a;(c) abstract a;(d) Boolean a;The question was asked during an internship interview.This intriguing question comes from Data Members in section Class Members & Types of Object Oriented Programming

Answer»

The CORRECT answer is (c) abstract a;

To explain: The abstract KEYWORD in the declaration of data members is not allowed. This is because the abstract keyword FEATURES can’t be used with the data members of the class. We can have all other SYNTAX given, but not abstract.

15.

Which among the following best describes member functions?(a) Functions which are defined within the class(b) Functions belonging a class(c) Functions in public access of a class(d) Functions which are private to classThis question was addressed to me in semester exam.My query is from Member Functions topic in division Class Members & Types of Object Oriented Programming

Answer» RIGHT CHOICE is (b) Functions belonging a class

Explanation: We can’t say that only functions that are defined inside class are MEMBER functions. There can be some inherited functions. THOUGH they doesn’t belong to the class but are property of the objects once inheritance is USED. So the nearest definition is functions belonging to a class.
16.

How many types of member functions are generally there in C++?(a) 2(b) 3(c) 4(d) 5I had been asked this question in a national level competition.My question is taken from Member Functions topic in portion Class Members & Types of Object Oriented Programming

Answer»

Correct CHOICE is (d) 5

Easy explanation - There are 5 TYPES of member functions that are generally provided in C++. NAMELY, SIMPLE, static, const, inline and friend member functions. Member functions are SPECIFIC to classes.

17.

How can a static member function be called in the main function?(a) Using dot operator(b) Using arrow operator(c) Using dot or arrow operator(d) Using dot, arrow or using scope resolution operator with class nameI had been asked this question by my college professor while I was bunking the class.I would like to ask this question from Member Functions topic in portion Class Members & Types of Object Oriented Programming

Answer»

Correct choice is (d) USING DOT, arrow or using scope RESOLUTION operator with class name

The best I can explain: The member functions can be called using only the dot operator or the arrow operator. But the static members can be called using directly the class name FOLLOWED by the scope resolution operator and static member function name. This is useful when you don’t have any object to call the member.

18.

What are inline member functions?(a) Member functions which can be called without object(b) Member functions whose definition is expanded in place of its call(c) Member functions whose definition is faster than simple function(d) Member function which is defined in single lineI got this question during an internship interview.My query is from Member Functions topic in chapter Class Members & Types of Object Oriented Programming

Answer»

The CORRECT option is (b) Member FUNCTIONS WHOSE definition is expanded in place of its call

Easy EXPLANATION - The member functions whose definition is expanded at the call, and no jump to function and return happened, are TERMED as inline functions. This is used to make the program faster and more efficient.

19.

What happens if non static members are used in static member function?(a) Compile time error(b) Runtime error(c) Executes fine(d) Executes if that member function is not usedThe question was asked in homework.Origin of the question is Member Functions topic in portion Class Members & Types of Object Oriented Programming

Answer»

Right option is (a) Compile TIME ERROR

The best I can explain: There must be specific memory space allocated for the data members before the static member functions USES them. But the space is not reserved if OBJECT is not declared. HENCE only if static members are not used, it leads to compile time error.

20.

Static member functions _____________(a) Contains “this” pointer for data members(b) Contains “this” pointer if used for member functions(c) Doesn’t contain “this” pointer(d) Doesn’t contain “this” pointer if member functions are referredI had been asked this question during an interview for a job.My query is from Member Functions topic in portion Class Members & Types of Object Oriented Programming

Answer»

Right CHOICE is (c) Doesn’t CONTAIN “this” pointer

The best EXPLANATION: The STATIC member functions doesn’t contain “this” pointer. Static member functions can’t be defined as const or VOLATILE also. These are restrictions on static member functions.

21.

How to access members of the class inside a member function?(a) Using this pointer only(b) Using dot operator(c) Using arrow operator(d) Used directly or with this pointerThis question was addressed to me in an online quiz.This is a very interesting question from Member Functions in section Class Members & Types of Object Oriented Programming

Answer»

The correct ANSWER is (d) USED directly or with this POINTER

The EXPLANATION is: The members of a class can be used directly inside a member FUNCTION. We can use this pointer when there is a conflict between data members of class and arguments/local function variable names.

22.

For overloading “( )”, “[ ]” or “->” operators, a class __________(a) Must use static member functions(b) Must use non-static member functions(c) Must be non-static member and should not be friend of class(d) Must use static member function or a friend member functionThis question was addressed to me during an interview.My question is based upon Member Functions in section Class Members & Types of Object Oriented Programming

Answer»

The correct answer is (C) MUST be non-static member and should not be FRIEND of class

To explain I would SAY: For overloading those operators for a class, the class must use non-static member function so that doesn’t remain common to all the objects, and each OBJECT can use it independently. The friend functions is also restricted so as to keep the security of data.

23.

If a virtual member function is defined ___________(a) It should not contain any body and defined by subclasses(b) It must contain body and overridden by subclasses(c) It must contain body and be overloaded(d) It must not contain any body and should not be derivedThe question was posed to me in homework.This interesting question is from Member Functions topic in portion Class Members & Types of Object Oriented Programming

Answer»

The correct answer is (a) It should not contain any body and DEFINED by subclasses

Explanation: The VIRTUAL functions are defined USING virtual keyword. These are made in order to make all the CLASSES to define them as the class gets inherited. INCREASES code understanding.

24.

Member functions of a generic class are _____________(a) Not generic(b) Automatically generic(c) To be made generic explicitly(d) Given default type as doubleI have been asked this question in an online quiz.My question is from Member Functions in chapter Class Members & Types of Object Oriented Programming

Answer»

Correct answer is (b) Automatically GENERIC

Explanation: When generic type is used in a CLASS, the functions are automatically generic. This is so because the functions would use the same type as defined to MAKE the class generic. The functions will get to know the type of DATA as soon as the generic class is used. It’s INBUILT feature.

25.

Member function of a class can ____________(a) Access all the members of the class(b) Access only Public members of the class(c) Access only the private members of the class(d) Access subclass membersThis question was addressed to me in semester exam.This interesting question is from Member Functions in division Class Members & Types of Object Oriented Programming

Answer»

Right OPTION is (a) Access all the members of the class

To EXPLAIN: The MEMBER functions has access to all the members of the class. Whenever data members of a class, which might be private, have to be MODIFIED, we make use of these member functions. This is more secure way to manipulate data.

26.

A member function can _______________ of the same class.(a) Call other member functions(b) Call only private member functions(c) Call only static member functions(d) Call only const member functionsI had been asked this question in class test.This interesting question is from Member Functions in section Class Members & Types of Object Oriented Programming

Answer»

Correct option is (a) Call other member functions

For EXPLANATION: We can call ONE function inside another function to access some data of class. A public member function can be USED to call a PRIVATE member function which directly manipulates the private data of class.

27.

Which member function doesn’t require any return type?(a) Static(b) Constructor(c) Const(d) Constructor and destructorI have been asked this question during an interview.My question comes from Member Functions in chapter Class Members & Types of Object Oriented Programming

Answer»

Right choice is (d) CONSTRUCTOR and destructor

For EXPLANATION: All the member FUNCTIONS work same as normal functions with syntax. But the constructor and destructor are also CONSIDERED as member functions of a class, and they never have any data type.

28.

Which among the following is not possible for member function?(a) Access protected members of parent class(b) Definition without return type(c) Access public members of subclass(d) Access static members of classThe question was posed to me in an international level competition.This key question is from Member Functions in section Class Members & Types of Object Oriented Programming

Answer»

Right choice is (c) ACCESS PUBLIC members of SUBCLASS

To explain: A member function of a class can only have the access to the members of its own class and parent classes if inheritance used. Otherwise a member function can never access the members of a subclass. Accessing static members of a class is possible by NORMAL and static member functions.

29.

What are local classes?(a) Classes declared inside a package(b) Classes declared inside a function(c) Classes declared inside a class(d) Classes declared inside structureThis question was posed to me in an internship interview.I would like to ask this question from Local Class topic in portion Class Members & Types of Object Oriented Programming

Answer»

The correct option is (b) CLASSES DECLARED inside a function

The EXPLANATION: The classes declared inside a package are available to all the functions and classes, HENCE can’t be called local. This is somewhat similar concept that we use to denote variables of a function. The classes declared inside functions will be local to them.

30.

All member functions of a local class must be ___________(a) Defined outside class body(b) Defined outside the function definition(c) Defined inside the class body(d) Defined at starting of programI had been asked this question in an interview.My query is from Local Class in portion Class Members & Types of Object Oriented Programming

Answer»

The correct choice is (c) Defined INSIDE the CLASS body

The EXPLANATION: There is a restriction on where the MEMBER functions of the local class should be define. Those MUST be defined inside the class body only. This is to reduce the ambiguity and complexity of program.

31.

Can local class members access/use the general local variables (except static, abstract etc.) of the function in which it is defined?(a) Yes, it can access with arrow operator(b) No, it can’t access with dot operator(c) Yes, it can access using dot operator(d) No, it can’t access In anywayThe question was asked in semester exam.The above asked question is from Local Class topic in portion Class Members & Types of Object Oriented Programming

Answer» CORRECT option is (d) No, it can’t ACCESS In anyway

Best explanation: The LOCAL variables of the functions are not available to the member functions of the class. This is done to reduce the ambiguity in variables and their access rules.
32.

Which type of data can a local class access from the function in which it is defined?(a) Static and extern(b) Abstract and static(c) Void and extern(d) Const and staticI had been asked this question by my college professor while I was bunking the class.I need to ask this question from Local Class in division Class Members & Types of Object Oriented Programming

Answer»

Correct ANSWER is (a) Static and extern

Easy explanation - The local classes have this feature to ACCESS the static and extern variables of the function in which those are DEFINED. This feature is available since these type of data are common to the program and is CREATED only one time. Run time CREATION and destruction of these variables is not done. The only restriction that may apply is those members must be constants.

33.

Local classes can access the type names and enumerators defined by the enclosing function.(a) True(b) FalseThe question was asked in an interview for job.My question is from Local Class topic in portion Class Members & Types of Object Oriented Programming

Answer»

The correct ANSWER is (a) True

Easiest explanation - This is a little TRICKY part with local classes. THOUGH the local class can’t access the general variables of the function but can access the types that are DEFINED INSIDE the function. This is because the whole definition of that type would be existing inside the class.

34.

Can static variables be declared inside a local class?(a) Yes, with public access specifier(b) Yes, anywhere as required(c) No, not possible in private access specifier(d) No, not possible anywayThis question was posed to me in an online interview.I would like to ask this question from Local Class topic in chapter Class Members & Types of Object Oriented Programming

Answer»

The correct answer is (d) No, not possible anyway

The explanation is: No, the STATIC variables can’t be declared inside a local class. This is because each time the function is CALLED, all the variables get created again and are DESTROYED as soon as the function is RETURNED. This WOULD have been possible id the static variable was of function.

35.

All the member functions of local classes are __________ by default.(a) Static(b) Inline(c) Abstract(d) VirtualThe question was posed to me in a national level competition.This question is from Local Class in division Class Members & Types of Object Oriented Programming

Answer» CORRECT option is (c) Abstract

The BEST I can EXPLAIN: All the members are defined INSIDE the class body. And when the member functions are defined inside the class body, they are made inline by default. If the definition is too complex, those are made NORMAL functions.
36.

The enclosing function has no special access to the members of the local class.(a) True(b) FalseI got this question during an online exam.Origin of the question is Local Class topic in division Class Members & Types of Object Oriented Programming

Answer» CORRECT option is (a) True

The best I can explain: This is a rule that the ENCLOSING FUNCTION doesn’t have any SPECIAL access to the members of the local class. This is done to maintain the security of class members. And to adhere to the rules of OOP.
37.

Which language can use inheritance with local classes?(a) Kotlin(b) Java(c) SmallTalk(d) SAP ABAPThis question was addressed to me in an interview for job.This intriguing question originated from Local Class topic in portion Class Members & Types of Object Oriented Programming

Answer» CORRECT option is (d) SAP ABAP

The explanation: Other language MIGHT SUPPORT inheritance with local classes but those doesn’t provide all the proper features of inheritance. Language SAP ABAP provides a way to implement inheritance with local classes EFFICIENTLY.
38.

How many local classes can be defined inside a single function?(a) Only 1(b) Only 3(c) Only 5(d) As many as requiredThe question was asked in examination.Origin of the question is Local Class in section Class Members & Types of Object Oriented Programming

Answer» CORRECT answer is (d) As many as required

The explanation: The LOCAL classes can be defined as required. There is no restriction on the number of local classes that can be defined inside a function. But all those classes MUST follow the rules and RESTRICTIONS.
39.

All the data members of local class must be ___________(a) Defined with declaration(b) Defined in constructor(c) Declared and defined in constructor(d) Declared using a member functionI have been asked this question in class test.My question is from Local Class in chapter Class Members & Types of Object Oriented Programming

Answer» CORRECT answer is (b) Defined in constructor

For explanation: The data members FOLLOW the same rules as of simple classes. Hence the data members must be DECLARED first. Then their definition must be given using the CONSTRUCTORS.
40.

Can two different functions have local class with same name?(a) Yes, since local(b) No, names must be different(c) No, scope doesn’t work here(d) No, ambiguity arisesThe question was asked during a job interview.Question is from Local Class in division Class Members & Types of Object Oriented Programming

Answer»

The correct ANSWER is (a) YES, since local

For EXPLANATION: The local classes can have same name if they belong to different functions. The classes would be local to those specific functions and hence can have same name. This is same as that of local variables CONCEPT.

41.

What is the scope of local class?(a) Within the class only(b) Within the function(c) Within the program(d) One time creation and live till end of programThe question was posed to me in an international level competition.I need to ask this question from Local Class in division Class Members & Types of Object Oriented Programming

Answer»

Correct CHOICE is (b) WITHIN the function

To explain I would say: The SCOPE of a local class is limited only within the function definition. The function can use the class as usual as local VARIABLES. The class gets destroyed as soon as the function is returned.

42.

Can a function, other than the enclosing function of local class, access the class members?(a) Yes, using object(b) Yes, using direct call(c) Yes, using pointer(d) No, can’t accessI had been asked this question during an interview.Asked question is from Local Class topic in division Class Members & Types of Object Oriented Programming

Answer» CORRECT ANSWER is (d) No, can’t ACCESS

Explanation: The local classes are local to the specific enclosing function. Other functions can’t access the class. EVEN if the pointers are USED, the class must be alive when the pointer is used. But this will not happen if the enclosing function is returned.
43.

Which among the following is the main advantage of using local classes?(a) Make program more efficient(b) Makes program execution faster(c) Helps to add extra functionality to a function(d) Helps to add more members to a functionThis question was addressed to me by my school teacher while I was bunking the class.Enquiry is from Local Class topic in section Class Members & Types of Object Oriented Programming

Answer»

The correct OPTION is (c) Helps to add extra functionality to a function

Easy explanation - The closest answer is to add more functionalities to a function or to MAKE some specific FUNCTIONS to be generic. Adding more members to a function can be DONE directly but to add some special functionality that are encapsulated, can be done USING local classes.

44.

Which among the following best describes a nested class?(a) Class inside a class(b) Class inside a function(c) Class inside a package(d) Class inside a structureThe question was asked during an interview.My question comes from Nested Class in portion Class Members & Types of Object Oriented Programming

Answer»

Correct option is (a) CLASS inside a class

To EXPLAIN: If a class is DEFINED inside another class, the inner class is termed as nested class. The inner class is local to the enclosing class. SCOPE MATTERS a lot here.

45.

Which feature of OOP reduces the use of nested classes?(a) Encapsulation(b) Inheritance(c) Binding(d) AbstractionThe question was posed to me during an online exam.My question is based upon Nested Class topic in portion Class Members & Types of Object Oriented Programming

Answer»

Correct CHOICE is (B) INHERITANCE

The best explanation: USING inheritance we can have the security of the class being inherited. The subclass can access the members of parent class. And have more feature than a NESTED class being used.

46.

How many categories are nested classes divided into?(a) 2(b) 3(c) 4(d) 5This question was posed to me in unit test.My doubt stems from Nested Class in chapter Class Members & Types of Object Oriented Programming

Answer»

Correct CHOICE is (a) 2

The EXPLANATION: The nested classes are divided into two MAIN categories. Namely, Static and non-static. The categories define how the classes can be used INSIDE another CLASS.

47.

Non-static nested classes have access to _____________ from enclosing class.(a) Private members(b) Protected members(c) Public members(d) All the membersThis question was addressed to me in final exam.Question is from Nested Class topic in portion Class Members & Types of Object Oriented Programming

Answer»

The correct option is (d) All the MEMBERS

The explanation is: The non-static nested class can ACCESS all the members of the enclosing class. All the data members and MEMBER functions can be ACCESSED from the nested class. Even if the members are private, they can be accessed.

48.

Static nested classes doesn’t have access to _________________ from enclosing class.(a) Private members(b) Protected members(c) Public members(d) Any other membersThis question was posed to me in an interview for internship.I'd like to ask this question from Nested Class topic in portion Class Members & Types of Object Oriented Programming

Answer»

The correct choice is (d) Any other members

Best explanation: The static nested class doesn’t have ACCESS to any other members of the ENCLOSING class. This is a rule that is made to ensure that only the data which can be COMMON to all the object is being ACCESSED by the static nested class.

49.

The nested class can be declared ___________________(a) Public(b) Private(c) Protected(d) Public, Protected, Private or Package privateThe question was posed to me by my college director while I was bunking the class.My doubt is from Nested Class topic in chapter Class Members & Types of Object Oriented Programming

Answer»

Correct answer is (d) PUBLIC, PROTECTED, PRIVATE or PACKAGE private

The best I can explain: The nested class can be declared with any specifier, unlike the outer classes which can only be declared public or package private. This is flexibility given for the nested class being a member of enclosing class.

50.

Use of nested class ____________ encapsulation.(a) Increases(b) Decreases(c) Doesn’t affect(d) Slightly decreasesI have been asked this question in an interview for job.Enquiry is from Nested Class in chapter Class Members & Types of Object Oriented Programming

Answer» RIGHT option is (a) Increases

To EXPLAIN I would say: The use of nested class increases encapsulation as the inner class is GETTING EVEN more grouped into the enclosing class. Firstly the class encapsulate the data, having nested classes can increase the encapsulation even further.