"The constructor Punkt(Punkt) is undefined",

0

Witam,
po napisaniu programu wyskoczyl mi taki blad. "The constructor Punkt(Punkt) is undefined",
Ktos wie jak to zaradzic? :)

public class Test{
    public static void main(String[]args){
        Punkt punkt = new Punkt(10, 20);
        System.out.println("Wspolrzedne to:");
        System.out.println("x: " + punkt.x);
        System.out.println("y: " + punkt.y);
    }
}

class Punkt{
    int x;
    int y;

    public Punkt(int a, int b){
        x = a;
        y = b;
    }
}

		public class Firma{

	     public static void main(String args[]){
		Punkt punkt1 = new Punkt(10, 20);
		System.out.println("Współrzędne 1 to: ");
		System.out.println("x1: "+punkt1.x);
		System.out.println("y2: "+punkt1.y);

		Punkt punkt2 = new Punkt(punkt1);                      <-"The constructor Punkt(Punkt) is undefined", 
		System.out.println("Współrzędne 2 to: ");
		System.out.println("x2: "+punkt2.x);
		System.out.println("y2: "+punkt2.y);
	}
}
}
3

Komunikat mówi wszystko... Twoja klasa Punkt nie posiada konstruktora który jako parametr przyjmuje inny obiekt klasy Punkt, jedyny konstruktor jaki posiadasz poza tym domyślnym to taki, który oczekuje na 2 parametry - int a oraz int b.

1

Przecież jedyny konstruktor jaki masz to:

public Punkt(int a, int b){

Widzisz taki który by miał:

public Punkt(Punkt p){

? Bo ja nie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1