Pages

Saturday 15 September 2012

Fundamentals of Java





OOPS Concepts




Abstraction : Hiding unneccessary data from user is called Abstraction access specifiers like public,private etc are used to provide different level in abstraction.




Encapsulation : Taking data and object in a single unity is called Encapsulation.A class is example for Encapsulation.




Inheritance : creating anew class from existing class is called Inheritance.reusability is main advantage in inheritance.




polymorphism : if single mthod performs different task is called polymorphism.







Abstraction

Hiding unnecessary things and showing the essential information.




Example: Suppose take a car: In that we will have breaks and stering and etc... Here when we are changing the gear box to up or bottom then gears will work but we don't know how they are managing internally and we don't no how it is working. As a driver we don't need to know how it is working internally when we are changing every time. That is the reason they will hide the wires and cables internally and they will show up only gear box to us.




Advantages: 1) Code will be clean and for managing it will be very easy







Inheritance

Acquiring the properties from super class to subclass.




Example: Suppose take two java classes Class A contains 2 variables and ClassB Extends Class A that means here ClassB can access the classA variables without declaring it. If we do this then the memory will be less and reusable.




Advantages: 1)Reusability of code




Encapsulation

Wrapping up of data and methods into a single unit.




Example: In our class we need to make all our varables and methods keeping together.




Advantage: Maintance will be good




Polymorphism

It means many forms. 2 types:

1) Compile time polymorphism

2) Run time polymorphism




Method overloading is an example for Compile time polymorphism and Method overriding is an example for Run time polymorphism

No comments:

Post a Comment