0% found this document useful (0 votes)
9 views2 pages

C# Practical

The document describes two C# console applications demonstrating inheritance and polymorphism. The first application implements inheritance with an 'Animal' class and a 'Dog' subclass, showcasing method usage and object creation. The second application illustrates polymorphism by defining a 'Printdata' class with overloaded print methods for different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

C# Practical

The document describes two C# console applications demonstrating inheritance and polymorphism. The first application implements inheritance with an 'Animal' class and a 'Dog' subclass, showcasing method usage and object creation. The second application illustrates polymorphism by defining a 'Printdata' class with overloaded print methods for different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

using System; Aim: To implement the inheritance in a C# Console

using System.Collections.Generic; application.


using System.Linq; Algorithm:
using System.Text; Step-1: Start the program.
Step-2: Create a class with name space.
Step-3: In the class shape create two method name
namespace Inheritance
as set width () and Set height() with one
{ Argument each.
class Animal Step-4: Create a class named rectangle.
{ Step-5: Create a method name getarea( ) in that
public string name; return the value width, height.
public void display() Step-6: In the main function create a new object
{ named RECT.
Console.WriteLine("I am an animal "); Step-1: Access the setwidth with value 5.
} Step-8: Access the set height method width value 7.
} Step-9: Involve the get area method and display the
area value.
class Dog : Animal
Step-10: Read a key and terminate the program.
{
public void getname()
{
Console.WriteLine("My Name is "+ name);
}
}
class program
{
static void Main(string[] args)
{
Dog labrador = new Dog();
labrador.name="rohu";
labrador.display();
labrador.getname();
Console.ReadLine();
}
}
}
using System; Aim: To implement the polymorphism in C#
using System.Collections.Generic; console application.
using System.Linq; Algorithm:
using System.Text; Step1: Start the program.
Step-2: Create a class with test data.
namespace Polymorphism Step-3: Create two method with add with three
{ arguments, and width two argument.
class Printdata Step 4: In the add method with two argument return
the value of A+B+C.
{
Step-5: In the main function new object with the
void print(int i)
name data class.
{ Step 6: Access the method function new Object
Console.WriteLine("Printing int: {0}", i); with name data class.
} Step-7: Access the method & width three argument
void print(double f) & store the result in add 2.
{ Step-8: Access the method add width two
Console.WriteLine("Printing int: {0}", f); arguments & store the result in add 1.
} Step-9: Display the add 1 and add 2 value.
void print(string s) Step-10: Read a key value a terminate the program.
{
Console.WriteLine("Printing int: {0}", s);
}
static void Main(string[] args)
{
Printdata p = new Printdata();
p.print(5);
p.print(500.263);
p.print("Hello C#");
Console.ReadKey();
}
}
}

You might also like