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

Lap

The document contains two C# programs demonstrating polymorphism and inheritance. The first program defines a class 'Printdata' with overloaded 'print' methods for different data types, while the second program defines an 'Animal' class and a 'Dog' subclass that displays the animal's name. Both programs utilize the 'Main' method to create instances and invoke their respective methods.

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Lap

The document contains two C# programs demonstrating polymorphism and inheritance. The first program defines a class 'Printdata' with overloaded 'print' methods for different data types, while the second program defines an 'Animal' class and a 'Dog' subclass that displays the animal's name. Both programs utilize the 'Main' method to create instances and invoke their respective methods.

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

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

namespace Polymorphism
{
class Printdata
{
void print(int i)
{
Console.WriteLine("Printing int: {0}", i);
}
void print(double f)
{
Console.WriteLine("Printing int: {0}", f);
}
void print(string s)
{
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();
}
}
}

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

namespace ConsoleApplication40
{
class Animal
{
public string name;
public void display()
{
Console.WriteLine("I am an animal");
}
}
class Dog : Animal
{
public void getname()
{
Console.WriteLine("My Name is "+ name);
}
}
class program
{
static void Main(string[] args)
{
Dog labrador = new Dog();
labrador.name="Jackey";
labrador.display();
labrador.getname();
Console.ReadLine();
}
}
}

You might also like