OOP Flashcards
(23 cards)
Define a class
A blueprint for creating objects; groups fields & methods.
Define an object
An instance of a class.
Define a method
Subprogram/code that performs a single task.
Give examples of access modifiers.
Private, public, protected.
Define a constructor
A special method that assigns values to object fields when created.
Define method overloading
Having multiple methods with the same name but different parameter lists in the same class.
Define method overriding
Subclass redefines a method from the superclass (same name, same parameters).
Method overriding in Java occurs when a subclass provides a specific implementation for a method that is already defined in its superclass
Define encapsulation
Combining attributes and behaviors into a single unit (one class)
Explain the reliability of encapsulation
- Promotes information hiding, where internal details of the class are not directly accessibly from the outside class
- Prevents external code from modifying the internal state of an object
- . By encapsulating the internal details, you have more control over the class, making it less prone to unintended misuse
Define an accessor method.
A typed method that returns a value from an object.
A method that gets (returns) a field’s value.
What does an access modifier do?
Controls visibility of class, method, or variable.
Define a mutator method.
A method that changes object fields but does not return a value.
A method that sets or changes a field’s value.
What is the purpose of encapsulation?
Protect data by hiding it and controlling access.
What is the advantage of OOP
Allows code reuse and easier program design
Define inheritance.
A class uses properties and methods from another class.
Define method resolution
- the appropriate method will be invoked (called) based on the type of the object declared in another class
- Ability of the programming language / java to determine which
method to called based on the method signature
Define a method signature.
The method name + number and types of parameters.
Define a superclass.
The parent class in an inheritance hierarchy.
Define a subclass.
A child class that inherits from a parent class.
What is a typed method versus a void method?
A typed method returns a value.
A void method does not return any value.
What is the difference between static and non static
Static Method - A method that belongs to the entire class instead of one instance of the class.
- Static fields and methods belong to a CLASS.
- Non-static fields and methods belong to an OBJECT
Explain why constants are useful in programming
- Constants are useful in programming when a value needs to remain fixed
throughout the program’s execution. - They provide a way to give meaningful names
to fixed values, making the code more readable and maintainable. - Constants also
make it easier to update a value in a single place in the code.
Define polymorphism
- One method behaving differently based on the object or parameters.
- allows objects of different classes to be treated as objects of a common superclass. This enables a single action to be performed in different ways, based on the specific object being used