Dec 29, 2019

INTERFACE ALLOWS PERFORMING MULTIPLE INHERITANCES IN C#

INTERFACE ALLOWS PERFORMING MULTIPLE INHERITANCES IN C#

In c #sharp normally we can’t perform the multiple inheritances as we done single or multilevel inheritance the compiler restricted to do such a process. But by using interface we are able to perform multiple inheritances that is explaining with the example below.

POINT TO PERFORM MULTIPLE INHERITANCES

When we going to perform multiple inheritance we should keep on eye to the following points.
1. In case of base class during inheriting the base class must come first before the interfaces. See            example
2. We can perform multiple inheritances of interfaces, in that case no matter which interface come          first.
3. The implementation of all interface abstract member can be done in a child class.

SYNTAX

[<Modifier>] Interface <IName1>
{
  Abstract members;         //but here we need not declare the members as abstract and public b,c
            by default all member will be public and abstract
}
        [<Modifier>] Interface <IName2>
{
  Abstract members;
}
         [<Modifier>] class <Name>: <IName1>, <IName2>
{
  Implementation members;
}

EXAMPLES

class Program
    {
        static void Main(string[] args)
        {
            Implementation Obj = new Implementation ();
            Obj.Add(12, 34, 67);
            Obj.Sub(34, 76);
INTERFACE ALLOWS PERFORMING MULTIPLE INHERITANCES IN C#, multiple inheritance in c#, multiple inheritance
interface allow us to perform multiple inheritance in c#
            Obj.Mul(12, 12);
            Obj.Div(122, 22);
            Obj.Rem(35, 4);
            Console.ReadKey();
        }
    }
    public interface ITest
    {
        void Add(int a, int b, int c);
        void Sub(int a, int b);
    }
    public interface ITest1
    {
        void Rem(int a, int b);
    }
    public class Test2
    {
        public void Mul(int a, int b)
        {
            Console.WriteLine(a * b);
        }
        public void Div(int a, int b)
        {
            Console.WriteLine(a / b);
        }
    }
    public class Implementation: Test2, ITest1, ITest
    {
        public void Add(int a, int b, int c)
        {
            Console.WriteLine(a + b + c);
        }
        public void Sub(int a, int b)
        {
            Console.WriteLine(a - b);
        }
        public void Rem(int a, int b)
        {
            Console.WriteLine(a / b);
        }
    }

PARTIAL CLASS IN C#

c# partial class, partial class, partial class examples, advantages of partial class
partial class in c#

PARTIAL CLASS

            The ability of splitting of a single class into multiple classes with the help of  the keyword ‘Partial’ known as partial class. This keyword is useful to split the functionality of method and interface.

SYNTAX

            [<Modifier>] partial class <Name>
{
  Class members;
}
[<Modifier>] partial class <Name>
{
  Class members;
}

EXAMPLE

            When we make two or more then partial class then at compilation time it compile as a class means combined all the class into one class and then compiled. Like this

Public partial class Test
{
  Public int a = 12;
  Public string name =”Meer”;
  Public void Info ( )
  {
   Console. WriteLine (“name ={0}   
    password ={1}”, a, name );
  }
}
Public partial class Test
{
  Public void login( )
  {
    Console. WriteLine (“you are now
   login into the partial class Test”);
  }
}

At a time of compilation it compile like

Public class Test
{
  Public int a = 12;
  Public string name =”Meer”;
  Public void Info ( )
  {
   Console. WriteLine (“name ={0}   
    password ={1}”, a, name );
  }
  Public void login( )
  {
    Console. WriteLine (“you are now
   login into the partial class Test”);
  }

}

ADVANTAGES OF PARTIAL CLASS

            There are some advantages when we declare a class as partial class.
            1.    Multiple developers can easily add their own program features such as method in the partial               class.
            2.    By making large and complex class into small class you can easily understand and maintain                 your application in efficient manner.

INTERFACE (class and interface) IN C#

c# interface, interface, interface in java, class and interface
interface in c#

INTERFACE

            “Interface is mechanisms in which we declare abstract members only, and it’s allowing us to build multiple inheritances.”
SYNTAX
Public Interface I<name>
{
  Defining abstract members;
}
Public class <name>: I<name>
{
  Implementation of abstract member;
}

POINTS TO DEFINE INTERFACE

            Some important points that should keep in mind when creating an interface.
        1.    All the member of interface must abstract, non-abstract member is not allowed.
        2.    In the child class of interface the abstract member should implement.
        3.    The member need not to declare public as well as abstract just like we done in abstract class,                here in interface all the members are public and abstract by default.
        4.    The name of interface is usually start with “I” capital I.
        5.    It allows us to use multiple inheritances in c#.
        6.    An interface can be inherited from another interface.
        7.    It’s not require to override the member but it’s up to you, you can override but not necessary.
        8.    At a time we can inherit a class and an interface in a child class.
EXAMPLE
            Public Interface IEvaluation
            {
              void Add (int a, int b);
              void Sub (int c, int d);
            }
            Public class Implementation: IEvaluation
            {
              Public void Add(int a, int b)
              {
                Console.WriteLine (a + b);
              }
              Public void Sub(int c, int d)
              {
                Console.WriteLine (c - d);
              }
            }
            Class Program
            {
              Static void main(string [ ] arg )
              {
                Implementation Obj = new Implementation ( );
                Obj. Add(24, 25);
                Obj. Sub(34, 76);
                Console. ReadKey ( )
              }
           
c# interface inherit from abstract class,interface methods in c#, difference between interface and abstract class and class
interface and abstract class

          DIFFERENCE BETWEEN CLASS, ABSTRACT CLASS AND                                                               INTERFACE


CLASS
Class contains only non-abstract members.
Class declare with the keyword ‘Class’ i.e.
<Modifier> class <Name>
{ }
Class member can be implemented at the current class i.e.
<Modifier> class <Name>
{
Implementation;
}
No child class need to implementation, it’s done with declaration time.
ABSTRACT CLASS `
Abstract class contains abstract and non-abstract members.
It declare with keyword ‘abstract class’ i.e.
<Modifier> abstract class<Name> { }
Abstract member of class cannot implement in the current class only declaration. The abstract member should declare with ‘virtual’ keyword
Child class needs to implement the abstract members.
INTERFACE
Interface contains only abstract class.
Interface is declare with the keyword ‘Interface’ i.e.
<Modifier> Interface <IName> { }
Interface member never implemented only declare in that interface.
Child class needs to implement the interface member.


Dec 28, 2019

ABSTRACT CLASS AND ABSTRACT METHOD


abstract method, abstract class in c++, abstract class c#, abstract class in oop
abstract class and method

ABSTRACT CLASS

            If any class defines abstract method or abstract member in it then the class will be an abstract class. We will use abstract modifier to indicate that that is an abstract class, like this
SYNTAX
            Public abstract class classname
           {
           }

ABSTRACT METHOD

            The method that contain without any method body is called abstract method. It’s necessary to use abstract keyword to declare a method as abstract. The method contain only the declaration of the method like this
SYNTAX
            Public abstract void Method ( );
  No body for the method only declaration.

RULE TO MAKE AN ABSTRACT CLASS.

           1.    Abstract class may contain abstract member and non-abstract members. Abstract member                     should declare with the keyword 'abstract'.
           2.    To access the non-abstract member the abstract member must be implementing in child class.               For implement we use override with the child class.
           3.    If the class only contain abstract member then it’s the responsibly to implement that member               in  child class otherwise the program not compile nor execute.
           4.    If the member declares as abstract then never implement in that current class.

 EXAMPLE

public abstract class Parent
    {
      public void Add(int a, int b )
        {
            Console.WriteLine(a + b);
        }
        public void Sub(int c, int d)
        {
            Console.WriteLine(c - d);
        }
        public abstract void Mul(int e, int f);
        public abstract void Div(int g, int h);
    }
    public class Child : Parent
    {
        public override void Div(int g, int h)
        {
            Console.WriteLine(g / h);
        }
        public override void Mul(int e, int f)
        {
           Console.WriteLine(e * f);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Child c = new Child();
            c.Add(12, 14);
            c.Div(18, 6);
            c.Mul(12, 12);
            c.Sub(12, 10);
            Console.ReadKey();
        }
    }

POLYMORPHISM IN C#


polymorphism in c#, method overriding , difference between overloading and overriding , polymorphism definition,polymorphism example
polymorphism definition 

POLYMORPHISM

            The process of re-implementation of parent class member in child class with same name but different behavior, state with the help of keyword ‘virtual’ and ‘Override’.

RULE TO PERFORMING POLYMORPHISM

            We have to follow some rule to perform polymorphism.
       1.    Inheritance should develop between classes to perform polymorphism.
       2.    Parent class member should rewrite in child class with new behavior.
       3.    Which the member should call, constructor will decide, on the base of constructor the member of either child or parent will call.
       4.    For the permission sake parent class member should declare virtual like this,
Public class Parent
{
  Public virtual void member ( )
}
           When a member declare virtual its mean it override able  in its child class.
        5.    Child member should declare with keyword override like this,
Public class child: Parent
{
   Public override void member ( )
}

METHOD OVERRIDING

            The redefining of parent class methods in child class with same name with different behavior and state. The parent class should virtual and the class member should define override.

SYNTAX

Public class Parent
{
  Public virtual void Testmethod ( )
     {
       Task;
     }
}
Public class Child: Parent
{
  Public override void Testmethod ( )
  {
     Task;   //changed behavior
  }
}

CALLING METHOD SYNTAX

Parent obj = new child ( );
Obj. Testmethod ( );  // here the constructor if child is calling thus the Testmethod of  
                                     child will execute

      DIFFERENCE BETWEEN OVERLOADING AND OVERRIDING 


Overloading
1.    The method of defining more than one method with same name but different parameters.
2.    Overloading means the methods have different behavior for each method.
3.    Overloading can perform between child parent classes and also in a class.
4.    To perform overloading we can define same name of method in child class without permission of parent class.



Overriding
1.    The method of redefining a parent class method in child class with same name same parameter.
2.    Overriding means the change in behavior of parent method and child method.
3.    Overriding can perform in between parent child class only.
4.    To performing overriding its necessary to take permission of parent class.


Dec 23, 2019

HALF ADDER AND FULL ADDER


HALF ADDER

            Half adder is like a small circuit that performs an addition tasks on only two inputs 0 and 1 for each input and gives us two outputs one is sum and the second is carryout number. Which consist of and exclusive OR gate that and AND gate including two inputs, where X-OR gate perform Sum and AND gate gives carry out number, which is more explain by logic diagram, logic symbol and truth table.

LOGIC DIAGRAM
half adder in dld, half adder, half adder truth table
half adder logic diagram
            
           Where the A and B is input and Sum = AÅB output of XOR and the Carry out number is A x B output of AND gate.

LOGIC SYMBOL:

half adder, half adder explanation, half adder in dld, half adder, truth table of half adder
halfadder logic symbol

TRUTH TABLE

                  A
B
AÅB
A x B
0
0
0
0
0
1
1
0
1
0
1
0
1
1
0
1

 FULL ADDER

            Process is same like half adder that perform addition and full adder also perform addition where the main difference between them is the number of input, where half adder have only two input and full adder have three inputs A, B and Cin. It also has two outputs one is sum and second is carryout number. See the logic diagram, logic symbol and truth table for understand to deep.

LOGIC SYMBOL 


full adder, full adder explanation, full adder truth table
fulladder logic diagram
          In this series three inputs are A, B and Cin where the final results are Sum and Carryout number as shown in figure. In full adder we used 5 gates two AND gate two XOR gate and one OR gate.

LOGIC SYMBOL

            Arrangement of two half adder to form a full adder in such a way that it look like as show
full adder, full adder in physics, full adder in dld, full adder truth table
full adder logic symbol
TRUTH TABLE
Inputs
Outputs
Cin
A
B
0
0
0
0
0
1
0
1
0
0
1
1
1
0
0
1
0
1
1
1
0
1
1
1
Sum
Carryout
0
0
1
0
1
0
0
1
1
0
0
1
0
1
1
1