using System;
class Book
{
// Fields
private string title;
private string author;
private int year;
// Parameterized Constructor
public Book(string title, string author, int year)
{
this.title = title;
this.author = author;
this.year = year;
}
// Properties
public string Title
{
get { return title; }
set { title = value; }
}
public string Author
{
get { return author; }
set { author = value; }
}
public int Year
{
get { return year; }
set { year = value; }
}
// Method to display book details
public void DisplayDetails()
{
Console.WriteLine($"Title: {title}, Author: {author}, Year: {year}");
}
}
class Program
{
static void Main()
{
// Creating an object of the Book class using the parameterized constructor
Book myBook = new Book("1985", "George Orwell", 1950);
// Accessing properties
Console.WriteLine($"Title: {myBook.Title}");
Console.WriteLine($"Author: {myBook.Author}");
Console.WriteLine($"Year: {myBook.Year}");
// Modifying properties
myBook.Year = 1951;
// Calling a method
myBook.DisplayDetails();
}
}