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

Try to clear up the basics, if basics are clear then you can go ahead with any difficult problem
Hey guys, To all the students i just want to convey that just clear up your basics so that they can help you solve anyu problem and you would achieve a great success. Regards, Ishani Chakraborty

How to create a Singleton class?
How to create a Singleton class: Q) What is a singleton class? A) In simple words, a singleton class is a class which can have only one instance at any point of time throughout the application and provides...

Overview on Auto IT and use in selenium webdriver
AutoIt v3 is a freeware BASIC-like scripting languages designed for automating the windows GUI and general scripting. It used a combination of simulated keystrokes, mouse movements and window/control manipulation...
S

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

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