Answer to Question #238643 in C# for Gayatri

Question #238643
Create a class named Product with the following private member variables.

Id of type long, ProductName of type string, SupplierName of type string and Include


Getters and setters. Include a 3-argument constructor, 2 argument constructor and a default constructor. Assume that most of the products are supplied by "Nivas" suppliers and in the 2-argument constructor set the value of supplier Name to "Nivas".

Include a method named Display. It does not accept any arguments and its return type is void. Display the details of the product in this method. The method prototype is void Display ();

Create another class and write a man method to test the above class.
Expert's answer
using System;
using System.Linq;

namespace ConsoleApplication1
    internal class Program
        public static void Main(string[] args)
            var p1 = new Product();
            var p2 = new Product(7568658965498749, "Gin");
            var p3 = new Product(5469836938744987, "Jija", "Jojo");

    class Product
        private long Id { get; }
        private string ProductName { get; }
        private string SupplierName { get; }

        public void Display()
            Console.WriteLine($"Id is {Id}");
            Console.WriteLine($"ProductName is {ProductName}");
            Console.WriteLine($"SupplierName is {SupplierName}");

        public Product(long id, string productName, string supplierName)
            Id = id;
            ProductName = productName;
            SupplierName = supplierName;
        public Product(long id, string supplierName)
            Id = id;
            ProductName = "Nivas";
            SupplierName = supplierName;
        public Product()
            Id = 0;
            ProductName = "";
            SupplierName = "";

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be the first!

Leave a comment

New on Blog