Я только начал свой второй курс Java в колледже, и я впервые вижу это. Какой смысл void setradius в конце кода. Код работает, если я удалю его, я просто не уверен, в чем смысл включить его в конструктор. Ниже приведен код с урока.public class TestCircle {
/** Main method */
public static void main(String[] args) {
// Create a circle with radius 1
Circle circle1 = new Circle();
System.out.println("The area of the circle of radius "
+ circle1.radius + " is " + circle1.getArea());
// Create a circle with radius 25
Circle circle2 = new Circle(25);
System.out.println("The area of the circle of radius "
+ circle2.radius + " is " + circle2.getArea());
// Create a circle with radius 125
Circle circle3 = new Circle(125);
System.out.println("The area of the circle of radius "
+ circle3.radius + " is " + circle3.getArea());
// Modify circle radius
circle2.radius = 100; // or circle2.setRadius(100)
System.out.println("The area of the circle of radius "
+ circle2.radius + " is " + circle2.getArea());
}
}
// Define the circle class with two constructors
class Circle {
double radius;
/** Construct a circle with radius 1 */
Circle() {
radius = 1;
}
/** Construct a circle with a specified radius */
Circle(double newRadius) {
radius = newRadius;
}
/** Return the area of this circle */
double getArea() {
return radius * radius * Math.PI;
}
/** Return the perimeter of this circle */
double getPerimeter() {
return 2 * radius * Math.PI;
}
/** Set a new radius for this circle */
void setRadius(double newRadius) {
radius = newRadius;
}
}
< /code>
Я смотрел пару уроков на YouTube о конструкторах в Java. Я не могу найти ответ через Google, и при этом я не понимаю, какой вопрос я должен задать.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -this-code
Какой смысл void setradius в конце этого кода? [дублировать] ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1737889006
Anonymous
Я только начал свой второй курс Java в колледже, и я впервые вижу это. Какой смысл void setradius в конце кода. Код работает, если я удалю его, я просто не уверен, в чем смысл включить его в конструктор. Ниже приведен код с урока.public class TestCircle {
/** Main method */
public static void main(String[] args) {
// Create a circle with radius 1
Circle circle1 = new Circle();
System.out.println("The area of the circle of radius "
+ circle1.radius + " is " + circle1.getArea());
// Create a circle with radius 25
Circle circle2 = new Circle(25);
System.out.println("The area of the circle of radius "
+ circle2.radius + " is " + circle2.getArea());
// Create a circle with radius 125
Circle circle3 = new Circle(125);
System.out.println("The area of the circle of radius "
+ circle3.radius + " is " + circle3.getArea());
// Modify circle radius
circle2.radius = 100; // or circle2.setRadius(100)
System.out.println("The area of the circle of radius "
+ circle2.radius + " is " + circle2.getArea());
}
}
// Define the circle class with two constructors
class Circle {
double radius;
/** Construct a circle with radius 1 */
Circle() {
radius = 1;
}
/** Construct a circle with a specified radius */
Circle(double newRadius) {
radius = newRadius;
}
/** Return the area of this circle */
double getArea() {
return radius * radius * Math.PI;
}
/** Return the perimeter of this circle */
double getPerimeter() {
return 2 * radius * Math.PI;
}
/** Set a new radius for this circle */
void setRadius(double newRadius) {
radius = newRadius;
}
}
< /code>
Я смотрел пару уроков на YouTube о конструкторах в Java. Я не могу найти ответ через Google, и при этом я не понимаю, какой вопрос я должен задать.
Подробнее здесь: [url]https://stackoverflow.com/questions/79379615/what-is-the-point-of-the-void-setradius-at-the-end-of-this-code[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия