All Flashcards
What is the purpose of a constructor?
To initialize the instance variables of a class when an object is created.
Why are instance variables often declared as private?
To encapsulate the data and control access to it from outside the class.
Explain the concept of pass-by-value.
When a primitive type is passed to a method, a copy of the value is passed. Changes to the parameter inside the method do not affect the original variable.
Explain how objects are passed as parameters.
A copy of the reference to the object is passed. Mutating the object inside the method will affect the original object.
What is the significance of the 'static' keyword?
It indicates that a variable or method belongs to the class itself, rather than to any specific instance of the class.
What are accessor methods used for?
Accessor methods are used to retrieve the values of private instance variables from outside the class.
What are mutator methods used for?
Mutator methods are used to modify the values of private instance variables from outside the class.
What is the purpose of documentation with comments?
To explain what your code does to document it properly.
What are the ethical and social implications of computing systems?
Privacy, security, inequality, censorship, and dependence.
What is the purpose of the 'this' keyword?
To access the fields and methods of the current object from within the object's own methods.
How is classes applied in real-world scenarios?
Classes are used to model real-world entities, such as bank accounts, cars, or employees, with their associated data and behaviors.
How is accessor methods applied in real-world scenarios?
Accessor methods are used to safely retrieve information about an object without allowing direct modification of its internal state.
How is mutator methods applied in real-world scenarios?
Mutator methods are used to update the state of an object in a controlled manner, often with validation or side effects.
How is static variables applied in real-world scenarios?
Static variables can be used to store application-wide settings or counters that need to be shared across all instances of a class.
How is the 'this' keyword applied in real-world scenarios?
The 'this' keyword is used to disambiguate between instance variables and local variables with the same name, ensuring that the correct variable is being accessed or modified.
How is comments applied in real-world scenarios?
Comments are used to explain complex logic, document API usage, and provide context for other developers who may need to maintain or extend the code.
What are the differences between accessor and mutator methods?
Accessor: Retrieves value of a private variable. Mutator: Modifies value of a private variable.
What are the differences between static and instance variables?
Static: Belongs to the class, shared by all objects. Instance: Belongs to each object, unique to each object.
What are the differences between global and local scope?
Global: Accessible throughout the program. Local: Accessible only within a specific block of code.