1/29
Flashcards reviewing key OOP principles, including classes, objects, inheritance, and polymorphism.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the primary focus in Object-Oriented Programming (OOP)?
OOP considers data first before actions are designed.
What is information hiding
Data is hidden and cannot be accessed by external methods.
What is modularity
The source code for an object can be written and maintained independently of the source code for other objects.
What is a class in OOP?
A construct that is used to define a distinct new type and is made up of Attributes/fields (Properties) that are grouped together to describe the object and Methods (Behavior) that describe what the object can do.
What are the three sections of a class diagram?
Class name, Attributes, and Methods.
What is an object in OOP?
A dynamic instance of a class; a software bundle of related state and behavior.
Why is a constructor needed in a class?
To create and instantiate an object of a defined class.
What is a default constructor?
A constructor that does not have any parameters and is used to initialize the attributes with default values.
What are the 2 types of parametrised constructors
Partially parametrised and filling parametrised
How do you instantiate an object in Java?
By using the 'new' keyword and calling the constructor of the class.
What is encapsulation in OOP?
A way of organizing data and functionality into a single unit by concealing the way the object is implemented; restricts access to data except through specified methods.
What does the principle of information hiding entail?
Declaring all fields and auxiliary methods as private in the class and limiting access to the data through Accessors and Mutators.
What are access specifiers used for in OOP?
To identify access rights for the data and member functions of the class; examples include public, private, and protected.
What is the purpose of a destructor or garbage collector?
To free memory and deallocate resources when an object's lifecycle is over.
What is an accessor or getter method?
A method in the class that makes private variables available to the main application or other units, providing read access to the attribute.
What is a mutator or setter method?
Provides write access to the attribute from the objects or other classes.
What is the purpose of auxiliary methods in a class?
Assist with the functionality of the class (calculations or formatting)
What is the purpose of toString() method?
Returns a formatted display of the objects attributes.
What is method overloading?
Two or more methods in a single class that have the same name but different types/order/number of parameters.
What is inheritance in OOP?
The process of creating a new class from an existing class in which objects of the new class inherit the attributes and behaviors of the existing class.
What is a subclass?
A class that inherits from another class.
What keyword is used in Java to indicate inheritance?
extends
What is method overriding?
Implementing a method in a derived class with the same signature as the base class method, allowing you to change the functionality of the inherited method.
What is polymorphism?
The ability of an object to take on different forms depending upon the situation, allowing objects to be processed differently based on their data type or class.
What is Compile time polymorphism?
Also known as Static binding. It is achieved through method overloading.
What is Runtime polymorphism?
Also known as Dynamic or late binding. It is achieved by overriding a base class method.
What does the 'static' keyword mean?
Linked to memory management
What is a Static Methods?
A static method belongs to the class rather than the object of a class.
What is a Static Block?
Used to initialize the static data member. It is executed before the main method at the time of class loading.
What is a Static Nested Class?
A static class created inside a class in java.