0% found this document useful (0 votes)
5 views

19# Overloading Constructors Object Oriented Programming

The document contains C# code for a 'Product' class that demonstrates constructor overloading in object-oriented programming. It includes three constructors: one that initializes all product properties, one that initializes only a subset, and a default constructor. The 'Program' class creates instances of 'Product' using the different constructors.

Uploaded by

Lesunter KLter
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

19# Overloading Constructors Object Oriented Programming

The document contains C# code for a 'Product' class that demonstrates constructor overloading in object-oriented programming. It includes three constructors: one that initializes all product properties, one that initializes only a subset, and a default constructor. The 'Program' class creates instances of 'Product' using the different constructors.

Uploaded by

Lesunter KLter
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

19# Overloading Constructors Object Oriented Programming

///////////////
//Product.cs//
//\\\\\\\\\\\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace darklter
{
internal class Product
{
public int productID { get; set; }
public string productName { get; set; }
public string productDescription { get; set; }
public int productStock { get; set; }
public float productPrice { get; set; }

public Product(int productID, string productName, string


productDescription, int productStock, float productPrice)
{
this.productID = productID;
this.productName = productName;
this.productDescription = productDescription;
this.productStock = productStock;
this.productPrice = productPrice;
}
public Product(int productID, string productName, int productStock, float
productPrice)
{
this.productID = productID;
this.productName = productName;
this.productStock = productStock;
this.productPrice = productPrice;
}
public Product() { }
}
}

///////////////
//Program.cs//
//\\\\\\\\\\\\

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Product p1 = new Product(1, "Milk", "Milky",5,150);
Product p2 = new Product(1, "Milk", 5, 150);
Product p3 = new Product();
}
}
}

You might also like