I think you should use a getter method. In other words, you need to create
an accessor.
These getter methods would return a statement. So, this problem would be
solved.
At the same time, it is not advisable to print output in an object class
unless it is for debugging and auditing.
This is an example of a getter method:
public static double getPointX()
{
return x;
}
public static double getPointY()
{
return y;
}
Above methods cann be applied to both classes. But, it all depends on how
you create it.
Thanks
On Tue, Feb 17, 2009 at 9:37 PM, prasad jedhe <[email protected]> wrote:
> -->what do i write in class segment to print the contents of pi n p2
> objects which i have created in main...i mean i want to print "segment is:
> (1,3)(3,3)" in segment class...am creating a small project "rectangle" using
> shared memory approach.i.e one segment with two points.. i need your help..
> thnx... :)
>
> package javaapplication1;
> public class Main
> {
> public static void main(String[] args)
> {
> point p1=new point(1,3);
> point p2=new point(3,3);
> p1.print();
> p2.print();
> segment s1=new segment(p1,p2);
> }
> }
>
> class point
> {
> private int x;
> private int y;
>
> point(int a, int b)
> {
> x=a;
> y=b;
> }
> void print()
> {
> System.out.println("Point is:("+x+","+y+")");
> }
> }
>
> class segment
> {
> private point p1;
> private point p2;
>
> segment(point a,point b)
> {
> System.out.println("segment is:");
> }
>
> }
>
>
> >
>
--
Regards
Abdul Rafiez
IT Dept
Segi KL
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---