Implement printing method in Demo.java, which reduces copy-paste code.