String name;
String surName;
int yearBorn;
int yearNow;
try (Scanner input = new Scanner(System.in)) { // input автоматически закроется
System.out.print("Your name:");
name = input.nextLine();
System.out.print("Your middle name:");
surName = input.nextLine();
System.out.print("What is the year now?");
yearNow = input.nextInt();
System.out.print("What year were you born?");
yearBorn = input.nextInt();
System.out.print("Hello, "+name+" "+surName+" ");
System.out.print("Your age: "+(yearNow-yearBorn)+"");
} catch(Exception e) {
//Обработка исключения, если возникло.
e.printStackTrace();
}
Scanner input = new Scanner(System.in);
try {
...
} catch(Exception e) {
e.printStackTrace();
} finally {
input.close(); // Закрываем
}
.class
получается объект Class, что бы в дальнейшем через рефлексию можно был извечь свойства во время выполнения.