Constructor Function
Lesson 26Author : 🦒
Last Updated : November, 2017
Code
public 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");
Console.WriteLine(book1.title);
Book book2 = new Book("Lord of the Rings", "JRR Tolkien");
Console.WriteLine(book2.title);
}
}