OOPS Concept With Real Life Example for Interviews
OOPS Concept With Real Life Example
allocated only when an object is created, i.e., when an instance of a class is created.
An architect will have the blueprints for a house….those blueprints will be plans that explain exactly what properties the house will have and how they are all layed out. However it is just the blueprint, you can’t live in it. Builders will look at the blueprints and use those blueprints to make a physical house. They can use the same blueprint to make as many houses as they want….each house will have the same layout and properties. Each house can accommodate it’s own families…so one house might have the Smiths live in it, one house might have the Jones live in it.
The blueprint is the class…the house is the object. The people living in the house are data stored in the object’s properties.
Abstraction: Abstraction means showing essential features and hiding non-essential features to the user.
For Eg. Yahoo Mail…
When you provide the username and password and click on submit button. It will show Compose, Inbox, Outbox, Sent emails…so and so when you click on compose it will open…but the user doesn’t
know what are the actions performed internally….It just Opens….that is essential; User doesn’t know internal actions …that is non-essential things…
For Eg. Tv Remote..
Remote is an interface between user and tv..right. which has buttons like 0 to 10 , on /of etc but we don’t know circuits inside remote…The user does not need to know..Just he is using an essential thing that is remote.
Encapsulation: Encapsulation means which binds the data and code (or) writing operations and methods in sthe ingle unit (class).
A car is having multiple parts..like steering, wheels, engine…etc..which binds together to form a single object that is car. So, Here multiple parts of cars encapsulates itself together to form a single object that is Car.In real time we are using Encapsulation for security purpose…
Encapsulation = Abstraction + Data Hiding.
Inheritance: Deriving a new class from the existing class, is called Inheritance.
String Street name;
class LatestAddress extends Address
public class Vishal
LatestAddress la = new LatestAddress();
//Assign variable accordingly…
In the LatestAddress class, we have total 6 properties..3 are inherited from Address class and 3 properties are
incorporated. So In the class Vishal we are declaring the object of class LatestAddress and then assign new variables using the properties of the previous base classes… So this is a nice example of inheritance..
2. Class – Blue print of Object
3. Encapsulation – Protecting our Data
4. Polymorphism – Different behaviors at different instances
5. Abstraction – Hiding our irrelevant Data
6. Inheritence – One property of an object is acquiring to another property of an object