Commit 5bdd7ad6 by Patryk Czarnik

toString przed zmainami

parent 426ff999
package p05_klasy_wstep;
public class Program3_Wypisywanie {
public static void main(String[] args) {
Osoba a = new Osoba("Ala", "Kowalska", 30);
System.out.println(a);
// różne sposoby wypisywanie obiektu na końcu korzystają z metody toString()
String s1 = a.toString();
String s2 = "obiekt: " + a;
String s3 = String.valueOf(a);
// String.valueOf(cokolwiek) jest najbardziej uniwersalnym sposobem zamiany innych rzeczy na string - zadziała dla obiektu, dla nulla, dla typów prostych
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment