Advertisement
davegimo

publicprivate

Sep 2nd, 2019
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class Test {
  2.  
  3.  
  4.     public static void main(String[] args) {
  5.         System.out.println();
  6.         System.out.println();
  7.  
  8.         Persona p = new Persona("davide", 23);
  9.  
  10.         p.setNome("franco");
  11.         p.anni = 14;
  12.         System.out.println(p.getNome());
  13.         System.out.println(p.anni);
  14.        
  15.         System.out.println();
  16.     }
  17. }
  18.  
  19.  
  20. %%%%%%%%%%%%%%%%%%%% CREA UN'ALTRA CLASSE
  21.  
  22. public class Persona {
  23.  
  24.    private String nome;
  25.    public int anni;
  26.  
  27.    public Persona(String n, int a) {
  28.        nome = n;
  29.        anni = a;
  30.    }
  31.  
  32.    public void setNome(String n) {
  33.        this.nome = n;
  34.    }
  35.  
  36.    public String getNome() {
  37.        return this.nome;
  38.    }
  39.  
  40.    private static void metodoPrivato() {
  41.        System.out.println("metodo privato");
  42.    }
  43.  
  44.    public static void main(String[] args) {
  45.      
  46.        metodoPrivato();
  47.    }
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement