Object VS Reference in java program

Object VS reference in java class programming?

This is basic different between them.

Object can access class data members. (data members -> methods and variables)

Reference can’t access directly class data members.

 

Let’s see example on Object VS Reference.

class A

{

void method1()

{

System.out.println(“Welcome in Invision Software Solution”);

}

}

class clEx1

{

public static void main(String args[])

{

//A a1;              // Ref

//a1.method1();            // Will Create an error

 

A a1 = new A();            // Object

a1.method1();  // give output…

A a2 = new A();

a2.method1();

 

// Ref -> Cannot able to call class method and variables

// Object -> Can able to call class method and variables

 

A a3;                           // Ref

a3 = new A();              // Object

 

a3.method1();

}

}

 

Output:

Welcome in Invision Software Solution

Welcome in Invision Software Solution

Welcome in Invision Software Solution

 

 

Video available on YouTube.

 

[sbscrbr_form]

If you have query about this blog, you can directly post comment or subscribe on website.


 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

279total visits,3visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint