Java Class: How to call and use a class from another class?

In my last post I have discussed about Float Type variable and how to add two float type variable.

Here I will share you about how to use and call a class from another class in Java.

 use a class from another class java

Here is the example:

class Room

{

float length;

float breadth;

void getdata(float  a, float b)

{

length=a;

breadth=b;

}

}

class RoomArea

{

public static void main(String args[])

{

float area;

Room room1=new Room();

room1.getdata(14,10);

area=room1.length*room1.breadth;

System.out.println(“Area:”+area);

}

}

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: