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 - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

jOOQ 3.10 Supports JPA Attribute Converter
One of the cooler hidden features in jOOQ is the JPADatabase, which allows for reverse engineering a pre-existing set of JPA-annotated entities to generate jOOQ code. For instance, you could write these...

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

Why Should We Learn Java Language?
Most of starters has confusion today that which of the programming language should be chosen to work on. It totally depends upon your need. As per my opinion, if you want to grow your career in IT industry...

Final modifier in Java
Can’t change value of variable if marked as final. It is best practice to mark method parameter as final if its value will not changes. Variable must be initialize either using Initializer block...
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