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

Syntax and example of java
Java syntax: Class Display - - class definition { Void Display() { System.out.println('welcome to Java') ; } Public static void main(String arcs) { Display D=new Display() ;--object creation D. Display } }

Java Hash Map internal implementation
1.Hash Map internal implementation: In hash map it will create an array of table (to store the {Key,Value} pair) which is of type java.util.HashMap.EntryThe Entry object contains {hash, key, next, value}...
R

ListIterator Example
public class ListIteratorEx { public static void main(String args) { List<String> li = new ArrayList<String>(); li.add("java1"); li.add("java2"); li.add("java3"); li.add("java4"); ListIterator...
S

Sarthak C.

0 0
0

Java Learning Tip
The easy way to learn any programatical language is just simple practices. Take a simple examples and practice daily one hour. And also go through the learning videos from youtube or somewhere else.

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