All About Basic


Home | Need Help? | Archives


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

December 15, 2010 2:17 am

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);

}

}

Posted by allaboutbasic

Categories: Java Basic Problems

Tags:

2 Responses to “Java Class: How to call and use a class from another class?”

  1. thanks for grow my knowledge

    Like

    By Harish Nath Swami on January 5, 2019 at 8:42 pm

  2. very good explanation

    Like

    By vasu on January 26, 2019 at 5:30 pm

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.