Wednesday, May 2, 2012

INHERITANCE


Two types:-Single level & Multilevel
There is a class & a child class. A class can access the result from child class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        class student
        {
            int rno;
            string name, address;
            public void getdata(int r, string n, string add)
            {
                rno = r;
                name = n;
                address = add;

            }
            public void display()
            {
                Console.WriteLine("ROLL NUMBER: "+rno.ToString());
                Console.WriteLine("Name: " + name);
                Console.WriteLine("Address: " + address);
            }
        }
        class accadamic : student
        {
            int rollno, mark1, mark2, total;
            public void getmarks(int r, int m1, int m2)
            {
                rollno = r;
                mark1 = m1;
                mark2 = m2;
            }
            public void result()
            {
                Console.WriteLine("Mark1: " + mark1.ToString());
                Console.WriteLine("Mark2: " + mark2.ToString());
                total = mark1 + mark2;
                Console.WriteLine("Total marks: " + total.ToString());

            }
        }
        static void Main(string[] args)
        {
            accadamic acd = new accadamic();
            Console.WriteLine("enter rollno,name,address");
            acd.getdata(Convert.ToInt16(Console.ReadLine()), Console.ReadLine(), Console.ReadLine());
            Console.WriteLine("enter marks");
            acd.getmarks(Convert.ToInt16(Console.ReadLine()),Convert.ToInt16(Console.ReadLine()),Convert.ToInt16(Console.ReadLine()));
            acd.display();
            acd.result();

            Console.WriteLine("end");
            Console.ReadLine();
        }
    }
}

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...