Already Passed
What are getter methods used for in a class?
✔✔Getter methods are used to access the private properties of an object.
What are setter methods used for in a class?
✔✔Setter methods are used to update or modify the private properties of an object.
How do you declare a class variable?
✔✔A class variable is declared using the `static` keyword so that it is shared among all objects
of the class.
What is the purpose of a class method?
✔✔A class method operates on the class itself rather than individual objects.
What is method overloading?
✔✔Method overloading is the ability to define multiple methods with the same name but
different parameters.
1
,What is the scope of a local variable?
✔✔A local variable is only accessible within the method or block in which it is defined.
What is the purpose of the `this` keyword in a class?
✔✔The `this` keyword refers to the current object, allowing access to its properties and methods.
How do you use a class as a client?
✔✔You use a class as a client by creating objects from it and calling its methods to perform
actions.
What is the difference between instance variables and class variables?
✔✔Instance variables are specific to each object, while class variables are shared among all
objects of the class.
How do you overload a method?
✔✔You overload a method by defining multiple versions with the same name but different
parameter lists.
2
,Why are getter and setter methods important?
✔✔Getter and setter methods control access to private properties, maintaining encapsulation and
data validation.
What is a default constructor?
✔✔A default constructor is a constructor with no parameters or one provided automatically if no
other constructor is defined.
What happens if you declare a variable with the same name as a class variable inside a method?
✔✔The local variable will shadow the class variable within the scope of the method.
Can a class have multiple constructors?
✔✔Yes, a class can have multiple constructors through constructor overloading.
What is encapsulation in object-oriented programming?
✔✔Encapsulation is the concept of restricting direct access to an object’s data and exposing it
through controlled methods.
3
, How do you access a private property of a class?
✔✔You access a private property using getter methods defined in the class.
What is the purpose of the `static` keyword in a class?
✔✔The `static` keyword defines variables or methods that belong to the class rather than any
object.
What is the lifecycle of a local variable?
✔✔A local variable is created when its scope is entered and destroyed when the scope is exited.
How can you call a class method?
✔✔You call a class method using the class name followed by the method name.
Why would you use method overloading?
✔✔Method overloading allows the same method name to handle different types or numbers of
arguments, making the code more flexible.
4