Advertisements
how can define private method in a class and using it in another class in a same package? my source code:
class rectangle{ int length,breadth; void show(int length,int bredth){ this.length=length; this.breadth=breadth; } public int calculate(){ int size; size=length*breadth; return(size); } } public class useOfthisoperator { public static void main(String args[]){ rectangle r=new rectangle(); r.show(5,6); int area=r.calculate(); System.out.println("this Area of rectangle is"+area); } }
Hi Friend,
Try the following code:
class rectangle{ int length,breadth; void show(int l,int b){ this.length=l; this.breadth=b; } public int calculate(){ int size; size=length*breadth; return size; } } public class useOfthisoperator { public static void main(String args[]){ rectangle r=new rectangle(); r.show(5,6); int area=r.calculate(); System.out.println("this Area of rectangle is: "+area); } }
Thanks