Java – Activity 2

Object - Instance of a class

 While working with classes, we declare a reference variable of a class type and then, typically, using the operator new, we instantiate an object of that class type and store the address of the object into the reference variable.

The statement:  Sum j = new Sum(); 

instantiate an object called j from class Sum.

Using the operator new to create a class object is called instantiation of the class.

public class Sum

{ double n1, n2;

   void Outs(double a, double b)

   { System.ou.println(“The sum is ” + s);

   }

   public static void main(String[] args)

   { Sum j = new Sum();

      j.n1 = 6.5;

      j.n2 = 8.5;

      j.Outs(j.n1, j.n2);

   }

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.