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.
Continue
Skips the rest of the loop’s body and moves to the next iteration.
Break
exit the loop
Method overloading
Methods having the same name but different in
parameters, it is known as Method Overloading.
Method overriding
If subclass (child class) has the same method as declared in the parent class,
it is known as method overriding in Java
Compile time polymorphism
It occurs during the compilation phase.
Decision made at compile time
Run time polymorphism
Method overriding.
It occurs during the execution of a program.
Decision made at runtime
Composition
The composition is a way to design or implement the has-a relationship. The has-a relationship is used to implement an instance variable that refers to another object
Synchronisation
Synchronization in Java is a technique used to control the access and execution of multiple
threads to ensure that only one thread can access a shared resource or code block at a time.
Coupling
separation of concerns is known as coupling. It means that an object cannot change or modify the state or behavior of other objects directly.
Threads
A thread in Java is a smaller unit of a process that can run concurrently with other threads within the same process.