0

How to make what i want?

class Polygon { private string name; public Polygon(string name) {

15th Sep 2022, 9:46 AM
TheMasterBee
TheMasterBee - avatar
4 ответов
+ 2
How to know what do you want to make ?
15th Sep 2022, 10:01 AM
Davinder Kumar
Davinder Kumar - avatar
+ 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.
17th Sep 2022, 5:39 AM
Filip Dobeš
0
Please read this before posting new questions https://www.sololearn.com/Discuss/333866/?ref=app
15th Sep 2022, 10:08 AM
Ipang
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
15th Sep 2022, 10:34 AM
TheMasterBee
TheMasterBee - avatar