0 evaluări0% au considerat acest document util (0 voturi)
61 vizualizări8 pagini
This document discusses encapsulation, data privacy, and polymorphism in object-oriented programming. It defines encapsulation as protecting data by hiding implementation details and controlling access through public methods. Data privacy is achieved through encapsulation by making fields private and accessing them via accessors and mutators. Polymorphism allows methods to perform differently based on the object, and is demonstrated through method overloading at compile-time and method overriding at run-time. The document poses questions about overloaded and overridden methods and preventing method overriding.
This document discusses encapsulation, data privacy, and polymorphism in object-oriented programming. It defines encapsulation as protecting data by hiding implementation details and controlling access through public methods. Data privacy is achieved through encapsulation by making fields private and accessing them via accessors and mutators. Polymorphism allows methods to perform differently based on the object, and is demonstrated through method overloading at compile-time and method overriding at run-time. The document poses questions about overloaded and overridden methods and preventing method overriding.
This document discusses encapsulation, data privacy, and polymorphism in object-oriented programming. It defines encapsulation as protecting data by hiding implementation details and controlling access through public methods. Data privacy is achieved through encapsulation by making fields private and accessing them via accessors and mutators. Polymorphism allows methods to perform differently based on the object, and is demonstrated through method overloading at compile-time and method overriding at run-time. The document poses questions about overloaded and overridden methods and preventing method overriding.
Assistant Professor CSE Department Encapsulation One of the fundamental OOP Concept Protective Barrier to prevent data being directly used outside the class Hides the implementation level details Example In Facebook people hides their age
Actual Detail is hidden inside Casule
UIE, CSE Deptt.
2 Data Privacy using Encapsulation Fields in a class are made private to prevent it to be accessed by code outside the class.
Private fields can be accessed only by using the public
methods in the class
It leads to Data Hiding or Privacy
UIE, CSE Deptt.
3 Data Privacy using Encapsulation Encapsulated data is accessed using the Accessor (getter) and Mutator (setter) methods.
Accessors Methods to retrieve the hidden data.
Mutators Methods to change hidden data.
UIE, CSE Deptt.
4 Polymorphism Capability of a method to do different things based on the object used for Accessing the method.
Two Types-
Compile time Polymorphism(Early Binding)
Runtime Polymorphism(Late Binding)
UIE, CSE Deptt.
5 Compile time Polymorphism Method Call is resolved by compiler
In java Compile time is implemented using Method
Overloading
Method overloading-One method can have different
signature and return type
UIE, CSE Deptt.
6 Run Time Polymorphism- JVM determines the method call at the runtime and not at the compile time.
The method being called is based on the object which on
which the method is triggered.
Method overriding is an example of runtime
polymorphism
UIE, CSE Deptt.
7 Questions to be Discussed Can overloaded methods be override too?