OOPS GENERAL Flashcards
Why OOPS?
The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
OOPS concepts
OOPs, Concepts: Polymorphism Inheritance Encapsulation Abstraction Class Object Method Message Passing
What is Polymorphism?
Differentiate between entities with the same name efficiently. This is done by Java with the help of the signature and declaration of these entities.
Polymorphism in Java is mainly of 2 types:
Overloading in Java
Overriding in Java
Inheritance
the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class. Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class.
Syntax of inheritance
class derived-class extends base-class { //methods and fields }
Encapsulation?
It is a protective shield that prevents the data from being accessed by the code outside this shield. Technically in encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of its own class in which they are declared. Encapsulation can be achieved by Declaring all the variables in the class as private and writing public GETTERS and SETTERS. Also defined as wrapping up of data under a single unit
Encapsulation is also known as ….?
Data Hiding, the data in a class is hidden from other classes
Abstraction?
Data Abstraction is the property by virtue of which only the essential details are displayed to the user. The trivial or the non-essentials units are not displayed to the user.
In java, abstraction is achieved by interfaces and abstract classes. We can achieve 100% abstraction using interfaces.
How to implement abstraction?
In java, abstraction is achieved by interfaces and abstract classes. We can achieve 100% abstraction using interfaces.
Class?
Class: A class is a user-defined blueprint or prototype from which objects are created.