void sound() { System.out.print("Animal"); }
}
class Dog extends Animal {
void sound() { System.out.print("Dog"); }
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.sound();
class Book {
String title;
Book(String title) {
this.title = title;
static { System.out.print("Static "); }
{ System.out.print("Init "); }
public Test() { System.out.print("Constructor "); }
new Test();
class Outer {
int x = 10;
class Inner {
int x = 20;
void print() { System.out.print(Outer.this.x); }
new Outer().new Inner().print();
List<String> list = new ArrayList<>();
list.add("A");
list.add(1, "B");
System.out.print(list.get(0));
try (BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
Function<Integer, String> func = n -> "Number: " + n;
System.out.print(func.apply(5));
Optional<String> opt = Optional.ofNullable(null);
System.out.print(opt.orElse("Default"));
Path path = Paths.get("test.txt");
Files.lines(path).forEach(System.out::println);