UrbanPro
true

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Object Oriented Programming Concepts :

Sravani D.
19/04/2017 0 0

Class :

Class is user defined data type. Class is a logical representation of an Object. That means Class is used to define an object, how you want to create your software object.

        For Example : An Engineer will design a car to build a real object CAR. Same like that we are designing a class to create software objects.

       After designing how many objects you want to create, using the same design you can create. All those objects are not same.

Syntax :                                                   Example :

class classname                                        class Car

{                                                               {

      data fields;                                             int wheels;

      blocks;                                                   {  

                                                                      wheels =4;        

                                                                     }

      methods;                                                void driving()  {

                                                                          statements;

                                                                     }

}                                                                }

Object :

Object is a physical representation of a class. Every object will contain 3 things.

1. State : Data fields of an object.

2. Methods : Behavior of  an object.

3. Identity : By name and memory address.

Syntax :                                                 Example :

// This is the Actual Object Creation

new constructor;                                                    new Car();   

 

// This is for giving some  reference name to object

classname referencename = new constructor; Car cr = new Car();

Abstraction :

Abstraction means " Minimizing inter-dependencies among separately written modules by defining strict external interfaces ". It is a methodology, By using Encapsulation, Abstract classes and interfaces we can achieve this Abstraction. That means by using Encapsulation concept we can hide the data and by using Abstract classes and interfaces  we can hide the implementation so that we can call Abstraction is nothing but hiding.

Encapsulation :

Encapsulation means wrapping/binding/packing of data and methods, operating on that data into a single component. So that we can restrict the data instead of preventing.

      That means by using getters and setters we can restrict the data by giving permissions to outside world.For which data you want to update/write to that data only provide setters otherwise if you want to give permission to read only then to that data provide only getters.

Example :

class Age

{

  private int age;

  private Date dob;

 

 public void setDateOfBirth(Date dob)

 {

    this.dob=dob;

    age = // Logic to calculate Age

 }

 

 public int getAge()

 {

    return age;

 }

}

 

In this example we are calculating age based on the DOB so we can't give age as input type so I did not write setter method for age and I don't want to expose exact date of birth to outside world so I did not provide getter for Date of Birth. 

Polymorphism :

Poly means Many and Morphism means Forms. So Polymorphism means one thing can act as a many forms based on where and how its exists.

  There are 2 types of polymorphism 

  1.  Compile-time 

  2.  Run-time

 

  The best example for polymorphism is ourself. we are only one person will behave like many persons based on where you exists with whom you exists like in class, theater, with friends, family, friends etc. 

  So that At object level methods indicating the behaviour, so to achieve polymorphism we use

  1. Method overloading

  2. Method Overriding

Inheritance :

Inheritance  is a concept of inheriting the properties and methods of one class into new class for the purpose of reusing the code. When the class need to have parent child relation ship we need to use inheritance concept. That means all the parents properties will not get to child and the child can add its own properties at this situation we can use inheritence instead of directly creating the objects.

    Java does not support multiple inheritance at class level.

Syntax :

class Parent

{

  //statements

}

class Child extends Parent

{

//statements;

}

"extends" is the keyword to build parent child relation ship.

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Java : Compile-time Versus Runtime optimization
While designing and development, one should think in terms of compile-time and run-time.It helps in understanding language basics in a better way.Let's understand this with a question below : What...
S

Easy way to remember Java keyword.
ACCESS MODIFIER ACCESS SPECIFIER abstract, assert, const, final, native, static, strictfp, super, synchronized, this, transient, void, volatile public, private, protected, default DATA...

Rohit Deshbhratar

1 0
0

Use of Service Locator Pattern
If we want to reuse the java code that should be the best approach w.r.t re-usability, maintanence and saving time to concentrate on our own businbess logic/requirement. In the similar approach many patterns...
M

Software Testing
Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifying that a software program...

Free selenium video tutorial
Hi All, Hope you are doing good. We uploaded few videos on Selenium components like IDE, RC and Webdriver on youtube channel you can watch them for free of cost. Kindly search with below link: ...
S
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more