Object-oriented programming (OOP Flashcards
What is a class?
A blueprint describing objects, and can be instantiated using a constructor to create an object
What is an object?
An object is an instance of a class
What does it mean to instantiate?
Create a new object
What is a method?
A piece of code that can be called by name, describes what the code in it can perform
What is a static method?
A method that belongs to the class, not specific to an object. Can be instantiated without creating an object of class
What is a constructor?
A special method that can create an object.
Superclass/base class
The class from which subclasses are derived. All classes are derived from Object class in Java
What’s a subclass?
A class that derives instance variables from a class
What is encapsulation?
making variables that can only be seen within a class. Public methods (like Getters and setters) are used to view the values of the variables.
What is polymorphism?
Subclasses can share traits with its parent class. Methods can have the same name but have different functionalities. Useful for when you want the method to perform different actions depending on parameters
What is overriding?
Overrides are created in a subclass with the same method name, but have different functionalities
What is an interface?
An interface provides the functionalities that a class must have. Good for making sure that classes have necessary methods
What is an abstract class?
A class that can’t be instantiated. and made for other classes to extend. Defines templates for other classes, and what functionalities they should have. Different from interfaces in that they can also define behavior.
What is extending vs implementing?
When extending, you want to use the functionalities of the class. When implementing, you just want to make sure that certain features are implemented
Private vs public vs protected
Private methods can only be seen within the class the variable is created in. Public can be accessed globally, and protected can only be seen by the package, subclass, and the class it’s in.