Principles of programming Flashcards
(44 cards)
What is a class in OOP?
A blueprint or definition of an object that defines attributes and methods.
What is an object?
An instance of a class with specific attribute values and behaviors.
What is instantiation?
The process of creating an object from a class definition.
What is a constructor?
A special method called when an object is instantiated to initialize attributes.
What are attributes?
Variables that hold data about the object.
What are methods?
Procedures or functions that define the behavior of an object.
What is encapsulation?
The bundling of data (attributes) and methods that operate on the data within a class, protecting it from outside access.
What are getters and setters?
Methods used to access (get) and modify (set) the values of private attributes.
What does it mean to make an attribute private?
The attribute is hidden from outside access and can only be accessed through methods inside the class.
What are access modifiers?
Keywords that control the visibility of class members, typically public, private, and protected.
What is polymorphism?
The ability of methods to behave differently based on the object they are called on, often achieved through method overriding.
What is inheritance?
A mechanism where a child class inherits attributes and methods from a parent class.
What is method overriding?
When a subclass provides a specific implementation of a method already defined in its parent class.
How is inheritance represented in UML?
With hollow-headed arrows pointing upward from the child class to the parent class.
What does ‘protected’ mean in OOP?
Attributes or methods accessible within their class and subclasses, but not from outside.
Why use encapsulation?
To protect data integrity by preventing direct access and modification of attributes.
What is meant by ‘message passing’ in OOP?
Objects communicate by calling each other’s public methods.
What is the difference between a superclass and a subclass?
Superclass is the parent class; subclass is the child class that inherits from the parent.
What is ‘composition over inheritance’?
A design principle that favors building classes by combining simpler, stand-alone classes rather than deep inheritance hierarchies.
What is the significance of using prewritten classes?
They promote code reuse and simplify system development.
Why might OOP lead to more complex systems?
Because of extensive message passing and the creation of many interacting objects.
What are some disadvantages of inheritance?
It can cause unintended behavior and tight coupling between classes.
How do public and private methods differ?
Public methods are accessible outside the class; private methods are only used within the class.
What is a UML class diagram?
A visual representation of a class showing its name, attributes, and methods.