//generalization - extracted common characteristic
class Product
{
int productcode;
string productname;
int price;
protected void getData()
{
Console.WriteLine("Input Product Information");
Console.WriteLine("Enter Product Code");
productcode = int.Parse(Console.ReadLine());
Console.WriteLine("Enter product Name");
productname = Console.ReadLine();
Console.WriteLine("Enter Price");
price = int.Parse(Console.ReadLine());
}
protected void showData()
{
Console.WriteLine("Show Product Information");
Console.WriteLine("Product Code={0} \n Product Name={1} \n Price={2} \n", productcode, productname, price);
}
}//class Product Ends
//specialization - to specific job + inherited product
class Book : Product
{
int noPages;
string Author;
internal void getBook()
{
getData();
Console.WriteLine("Input Book specific Information");
Console.WriteLine("Enter No of Pages");
noPages = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Name of Author");
Author = Console.ReadLine();
}
internal void showBook()
{
showData();
Console.WriteLine("Show Book specific information");
Console.WriteLine("Pages={0} \n Author={1}", noPages, Author);
}
}//Book Class Closed
//specialization - to specific job + inherited product
class Pen : Product
{
string b;
string cink;
internal void getPen()
{
getData();
cink = Console.ReadLine();
Console.WriteLine("Enter Brand Name");
b = Console.ReadLine();
}
internal void showPen()
{ showData();
Console.WriteLine("Brand={0} \n Ink Color={1}", b,cink);
}
}
class CallingClass
{
public static void Main()
{
Console.WriteLine("****BOOK *****");
Book b=new Book();
b.getBook();
b.showBook();
Console.WriteLine("****PEN *****");
Pen p=new Pen();
p.getPen();
p.showPen();
Console.ReadKey();
}
class Product
{
int productcode;
string productname;
int price;
protected void getData()
{
Console.WriteLine("Input Product Information");
Console.WriteLine("Enter Product Code");
productcode = int.Parse(Console.ReadLine());
Console.WriteLine("Enter product Name");
productname = Console.ReadLine();
Console.WriteLine("Enter Price");
price = int.Parse(Console.ReadLine());
}
protected void showData()
{
Console.WriteLine("Show Product Information");
Console.WriteLine("Product Code={0} \n Product Name={1} \n Price={2} \n", productcode, productname, price);
}
}//class Product Ends
//specialization - to specific job + inherited product
class Book : Product
{
int noPages;
string Author;
internal void getBook()
{
getData();
Console.WriteLine("Input Book specific Information");
Console.WriteLine("Enter No of Pages");
noPages = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Name of Author");
Author = Console.ReadLine();
}
internal void showBook()
{
showData();
Console.WriteLine("Show Book specific information");
Console.WriteLine("Pages={0} \n Author={1}", noPages, Author);
}
}//Book Class Closed
//specialization - to specific job + inherited product
class Pen : Product
{
string b;
string cink;
internal void getPen()
{
getData();
cink = Console.ReadLine();
Console.WriteLine("Enter Brand Name");
b = Console.ReadLine();
}
internal void showPen()
{ showData();
Console.WriteLine("Brand={0} \n Ink Color={1}", b,cink);
}
}
class CallingClass
{
public static void Main()
{
Console.WriteLine("****BOOK *****");
Book b=new Book();
b.getBook();
b.showBook();
Console.WriteLine("****PEN *****");
Pen p=new Pen();
p.getPen();
p.showPen();
Console.ReadKey();
}
No comments:
Post a Comment