// tak wygląda konstruktor, zauważ, że "Kolo" napisane jest z dużej litery oznacza to, że jest to konstruktor
public Kolo (double x, double y, double r) {
this.x = x;
this.y = y;
this.r = x;
}
// tak wygląda metoda, nazwy metod zaczynamy od małej litery i tutaj nie ma "Kolo" tylko "kolo".
public void kolo (double x, double y, double r) {
System.out.println(x + y + r);
}
// Konstruktor różni się od metody tym, że konstruktur buduje strukturę obiektu np:
Kolo kolo = new Kolo (2.0, 4.5, 5.5);
// natomiast metody zwracają obliczenia np:
public double kolo(double x, double y, double r) {
double result = x + y + r;
return result;
}
// lub coś wyświetlają np:
public void kolo(double x, double y, double r) {
System.out.println(x + " " + y + " " + r);
}
// jak wcześniej zaznaczyłem metody zaczynamy od małej litery natomiast nie zaleca się używania takiej samej nazwy jak klasa "Kolo" i metody "kolo" musimy nazwę metody delikatnie zmienić np showKolo lub koloPrint itp w zależności co funkcja ma robić. Wyżej napisałem funkcje tak samo jak nazwę klasy dla lepszego zrozumienia.
If the commented out line is supposed to be a constructor then it is wrong. A constructor does not have a return type. If that line is meant to be a method then it is bad style.
0
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.