oop
oop
Encapsulation?
-it basically the bundling of data and methods that operate on the data into a
single unit, known as a class. It hides the internal state of an object and only
exposes the necessary methods to interact with it.
21)Inheritance?
-mechanism by which a class can inherit attributes and methods from another
class.it increase code reusability and it also achives runtime polymorphism
22)Polymorphism?
-ability of objects to take on multiple forms.
-of two types based on the time when the call to the object or function is
resolved.
-Compile-time Polymorphism (Static Polymorphism):
Compile-time polymorphism refers to the polymorphic behavior that is resolved at
compile time.
It is achieved through method overloding, where multiple methods with the same name
but different parameter lists are defined within the same class.
The appropriate method to execute is determined by the compiler based on the number
and types of arguments passed to the method.
-Runtime Polymorphism (Dynamic Polymorphism):
Runtime polymorphism refers to the polymorphic behavior that is resolved at
runtime.
It is achieved through method overriding, where a subclass provides a specific
implementation of a method that is already defined in its superclass.
The appropriate method to execute is determined by the JVM based on the type of the
object at runtime.
23)Abstraction?
-simplifies complex systems by modeling classes based on their essential
characteristics and ignoring irrelevant details. It enables the creation of
abstract data types and interfaces, allowing for code reuse and modular design.
24) difference between Composition and Inheritance?
-Composition involves creating complex objects by combining simpler objects. It
allows for better encapsulation and flexibility.
-Inheritance involves creating new classes based on existing ones, inheriting their
attributes and methods.it can lead to tight coupling and less flexibility.