Object Oriented Programming Flashcards
Constructor vs. Method Facts:
Constructor
- A constructor is used to initialize the state of an object.
- A constructor must not have a return type.
- the constructor is invoked implicitly.
- The Java compiler provides a default constructor if you don’t have any constructor in a class.
- the constructor name must be the same as the class name.
Describe object-oriented programming?
A methodology or paradigm to design a program using classes and objects.
It includes concepts such as: Object, Classes, Inheritance, Polymorphism, Abstraction, Encapsulation
One of the 4 pillar of OOP is Encapsulation. What is Encapsulation ?
Encapsulation is a process of wrapping code and data together into a single unit
We can encapsulate an entire class by making all the data members of the class private (data hiding). We can use the getter and setter methods.
What is a parameterized Constructor ?
A parameterized constructor is one that has a specific number of parameters. It’s used to provide different values to the distinct objects.
What is Constructor Overloading ?
Constructor overloading is when there are more than one constructor with different parameter lists. Each constructor performs a different task. They are differentiated by the number of parameters in the list and their list types.
What is the default constructor ?
The default constructor is a no-args constructor that the Java compiler inserts automatically. It contains a default call to super()
What is method overloading ?
Method overloading is when a class has multiple methods of the same name, but different in parameters.
A method can be overloaded by :
- changing number of arguments
- changing the data type
This is a compile time polymorphism
What is an abstract method ?
A method that is declared as abstract and does not have implementation
What are some advantages of inheritance ?
- Method Overriding
2. Code Reusability
What is the extends keyword ?
The extends keyword indicates that you are making a new class that derives from an existing class.
What are the 2 types of constructors ?
Default and Parameterized
Constructor vs. Method Facts:
Method
- A method is used to expose the behavior of an object.
- A method must have a return type.
- The method is invoked explicitly.
- The method is not provided by the compiler in any case.
- The method name may or may not be the same as class name.
When is a constructor called ?
A constructor is called when an object is created.
What is generalization (abstraction)
Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass.
What is an object?
Any entity that has state and behavior. It can be defined as an instance of a class.
Ex. chair, pen, table, keyboard