0
How to make what i want?
class Polygon { private string name; public Polygon(string name) {
4 Answers
+ 2
How to know what do you want to make ?
+ 1
Its because its private varialble, and you have no acess from oitside the class, you have two option. Make it public, or use getter metod. Or, maibe I am wrong, but in C# working something that is named readonly. Is something similar in java ? ... yes in java is final keyword. use " pubblic final" instat private.
0
Please read this before posting new questions
https://www.sololearn.com/Discuss/333866/?ref=app
0
I want to make a class polygon, so that I can't change its name or number of sides except when doing the instance (object)
Like this:
class Polygon
{ private int numberOfSides;
private string name;
public Polygon(numberOfSides, name);
{ this.name = name;
this.numberOfSides = numberOfSides; }
}
Now when I want to get the name in the main method it can't be gotten:
Polygon square = new Polygon(4, "square");
Console.WriteLine(square.name);
WHERE IS THE PROBLEM