All Flashcards
What is the definition of a class?
A blueprint for objects, containing variables and methods.
What is an instance variable?
A variable that stores data within a class.
What is a constructor?
A special method to create and initialize objects of a class.
What is an accessor method?
A method (getter) used to retrieve the value of a private variable.
What is a mutator method?
A method (setter) used to modify the value of an instance variable.
What is a static variable?
A variable that works across all objects of a class, accessible without creating an object.
What is a static method?
A method that works across all objects of a class, accessible without creating an object.
What is scope in programming?
The visibility and accessibility of variables, functions, and other elements of a program.
What is global scope?
Visibility and accessibility of an element throughout the entire program.
What is local scope?
Visibility and accessibility of an element within a specific block of code.
What does the 'this' keyword refer to?
The current instance of an object.
What is a comment in Java?
A piece of text that the computer will not recognize as code and will not try to execute.
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.
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.