Constructor Function
Lesson 28Author : 🦒
Last Updated : October, 2017
Code
class Book{
public String title;
public String author;
public Book(String title, String author){
this.title = title;
this.author = author;
}
}
public class App{
public static void main(String [] args){
Book book1 = new Book("Harry Potter", "JK Rowling");
System.out.println(book1.title);
Book book2 = new Book("Lord of the Rings", "JRR Tolkien");
System.out.println(book2.title);
}
}