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
What is method overriding ?
Method overriding is when a subclass has the same method as declared in the parent class
- Used to provided the specific implementation of a method which is already provided by its superclass.
- A static method cannot be overridden.
- Runtime polymorphism
What are some advantages of OOP over Procedural Oriented Programming?
- OOP makes development and maintenance easier as project size increases.
- OOP provides data hiding
What is a constructor ?
A constructor is called when an instance of the object is created, and memory is allocated for the object. Used to initialize the object
What are the 3 types of inheritance in java ?
single, multilevel, and hierarchical
What is an abstract class ?
An abstract class is one that is declared as abstract. It needs to be extended and its method implemented. It cannot be instantiated.
One of the four pillars of OOP is Inheritance. Describe Inheritance.
Inheritance is a mechanism in which one object acquires all of the properties and behaviors of a parent object.
The idea behind it is that you can create new classes that are built upon existing classes. When inheriting, you can reuse methods and fields of the parent class and also add new ones.
It represents the IS-A relationship which is known as a parent-child relationship
What is Sub Class/Child Class ?
Subclass is a class which inherits the other class. It is also called the derived classes, extended class, or child class
What are the 2 ways to achieve abstraction ?
- Abstract class
2. Interface
One of the 4 pillars of OOP is Abstraction. Define Abstraction.
Abstraction is a process of hiding the implementation details and showing only functionality to the user. It focuses on what the object does and not how it does it.
What is Specialization ?
Specialization means creating new subclasses from an existing class. It certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.
What is a class?
A class is a “blueprint from which individual objects are created”. It’s a template that is used to create objects, and to define object data types and methods that may be used by the object.
What is a Super class/Parent class
A Superclass is the class from where a subclass inherits the features. It is also called a base class or parent class.
One of the four pillars of OOP is Polymorphism. Describe Polymorphism
Polymorphism is the ability of an object to take on many forms. It allows us to perform a single action in many ways.
It occurs when a parent class reference is used to refer to a child class object.