Oops concept Flashcards
Inheritance
When one object acquires all the properties and behaviors of a parent object, it is
known as inheritance. It provides code reusability. It is used to achieve runtime
polymorphism.
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated
class because all the data members are private here.
Abstraction
Hiding internal details and showing functionality is known as abstraction. For
For example, we don’t know the internal processing of the phone
In Java, we use abstract class and interface to achieve abstraction.
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something.
we use method overloading and method overriding to achieve
polymorphism.
Class
The collection of objects is called class. It is a logical entity.
Class is a blueprint of method
Object
Any entity that has state and behaviour is known as an object. For
For example, a chair, pen, table, keyboard, bike, etc. It can be physical or
logical.
Constructor
A constructor is a special method used to initialize objects when they are created.
It has the same name as the class and doesn’t have a return type.
Constructors are called automatically when an object is instantiated using the new keyword.
Instance Variable
Variables declared in a class but outside any method. They belong to instances of the class and each object gets its own copy.
Local variables
Variables declared within a method or a block. They exist only within that method or block and are not accessible outside.
Static variable
Also known as class variables, these are declared with the static keyword. They are shared among all instances of a class and exist independently of any particular instance.
This
Refers to the current instance of the class. Used to differentiate instance variables from local variables when they have the same name.
Static
Denotes a variable or method that belongs to the class rather than an instance. It is shared among all instances of the class.
New
Used to create an instance of a class. Allocates memory and initializes the object.
Super
Refers to the superclass or parent class. Used to invoke methods or access fields from the superclass.
Final
Indicates that a variable, method, or class cannot be changed or extended. For variables, it means a constant value.