r/javahelp • • Jul 27 '22

Need help with this code

I am trying to create a class called point which will have an x and y as coordinates however error squiggles show up and it's not running can someone point out the problem btw the code is not complete

public class Circle_class {
class Point(int x,int y)
    {
int x;
int y;
        x = x;
        y = y;
    }
class circle
    {
double radius;
Point center;
    }
}

0 Upvotes

8 comments sorted by

View all comments

1

u/geeksforgeeks Aug 05 '22

Here in the code you have mixed up the code of class declaration and constructors. We cannot define parameters in the class declaration and to assign values to the data members we use something called constructors which have the same name as that of class. You have to create the constructor inside the class. It will be like Point(int x,int y){this.x=x; this.y=y;}. This is what causes the error as you can’t define parameters in class declaration. So remove it from there and add a constructor to initialise the data members.

1

u/[deleted] Aug 07 '22

Oh my god is this the real geeks for geeks from the website

1

u/geeksforgeeks Aug 08 '22

It is indeed the real GeeksforGeeks portal, now here to connect with you guys on Reddit