Příklad - deklarace třídy Person

  • deklarujme třídu objektů - lidí

    public class Person { 
    
       protected String name; 
       protected int age; 
    
       public Person(String n, int a) { 
          name = n; 
          age = a;
       }
    
       public void writeInfo() { 
          System.out.println("Person:");
          System.out.println("Name "+name); 
          System.out.println("Age  "+age); 
       }
    } 
    
  • Použijme ji v programu -

    1. vytvořme instanci - objekt - typu Person

    2. vypišme informace o něm