C# class and constructor – programs for practice

Q) What is output of C# code? class Base { public Base() { Console.WriteLine(“Base class constructor”); } } class Child : Base { public Child() { Console.WriteLine(“Child class constructor”); } } class Program { static void Main(string[] args) { Child c = new Child(); } } [su_spoiler title=”View Answer” style=”fancy” icon=”folder-2″] Output: Base class constructor … Read more C# class and constructor – programs for practice

C# abstract class- programs for practice

Q) What is output of the following program? abstract class Customer { public void Print() { Console.WriteLine(“Print Method”); } } class Program { static void Main(string[] args) { Customer c = new Customer(); c.Print(); } } Output: Print method Compiler error [su_spoiler title=”View Answer” style=”fancy” icon=”folder-2″] Answer: B We cannot create an instance of the … Read more C# abstract class- programs for practice

C# Interface – Programs for Practice

Q) What is output of C# code? interface IAccount { string AccountInfo(); void process(); } class SavingAccount : IAccount { public string AccountInfo() { return “Saving Account”; } public void process() { Console.WriteLine(“Process saving account”); } } class Program { static void Main() { SavingAccount account = new SavingAccount(); Console.WriteLine(account.AccountInfo()); account.process(); } } Q) What … Read more C# Interface – Programs for Practice

C# Inheritance – programs for practice

Q) What is output of below C# code? class Car { public void run(){ Console.WriteLine(“Car is running”); } } class Maruti : Car { public void run(){ Console.WriteLine(“Maruti Car is running”); } } class Program { static void Main(string[] args) { Car c = new Maruti(); c.run(); } } Q) What is output of C# … Read more C# Inheritance – programs for practice