Lab Task # 4: Sir Faheem Ahmed Khan
Lab Task # 4: Sir Faheem Ahmed Khan
Lab Task # 4
4.1 Examine the following code. What is true about the variables and methods within the class NY
Customer?
Ans:
They are private. They can be accessed by their classes. They can be accessed only in subclasses. They are
protected
Ans:
Access modifiers are the keywords which are used Non-access modifiers are those keywords that do not
with classes, variables, methods, and constructors to have anything related to the level of access but they
control their access level. provide a special functionality when specified.
Public Final
The members of a class that are declared public are Final keyword can be used with variable, method or
easily accessible from any part of the program. All class. It prevents from its content from being
data members and member functions of a class are modified. When declared with class, it prevents the
public by default. class from being extended.
Private Static
The members of a class that are declared private are The static modifier is used with class variables and
accessible within the class only, private access methods which can be accessed without an instance
modifier is the most secure access modifier. Data of a class. Static variables have only single storage.
members of a class are declared private by adding a All objects share the single storage of static variable.
double underscore ‘__’ symbol before the data
member of that
class.
Protected Abstract
The members of a class that are declared Abstract can be used with class and methods. An
protected are only accessible to a class derived from abstract class can never be instantiated and its purpose
it. Data members of a class are declared protected by is only to be extended. Abstract methods are declared
adding a single underscore ‘_’ symbol before the data without body.
member of that class.
classA
{
privateA()
{
//First Constructor
}
privateA(inti)
{
//Second Constructor
}
}
Explain the answer in with reason and justify through python code.
Ans:
No, you can’t create sub classes to that class which has only private constructors. We can’t
Example:
Python code:
class Student:
schoolName = 'XYZ School' # private class attribute
Output: