Pages

Thursday, March 28, 2013

What is Abstract method?


Abstract method doesnot provide implementation and forces derived class to override the method.

There are following ways we can make use of Abstract Classes and Methods

1.We can create Non-Abstract methods inside Abstract Class, and Inherited Class can use this method.

See the Example below

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

namespace AbstractMethod1
{
    abstract class Test
    {
        public void MethodInAbstract()
        {
            Console.WriteLine("NonAbstract Method Called");
            Console.ReadKey();
        }
    }

    class Inherit : Test
    {
    }
    class Program
    {
        static void Main(string[] args)
        {
            Inherit obj = new Inherit();
            obj.MethodInAbstract();
        }
    }
}

In above program Test is Abstract Class MethodInAbstract is Non Abstractmethod. Another Class Inherit inherited the Abstract Class Test. Now we created object for
Inherit and called the MethodInAbstract method.

More Observations:
Abstract class will starts with keyword 'Abstract'
We can not create object for abstract class
Test obj=new Test(); it will show the error message 'Cannot create an instance of the abstract class or interface 'AbstractMethod1.Test'

2.Abstract method is meant by method which is not having any body, Who ever class inherited this Abstract Class that class must be override the
abstract methods.

Ex:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbstractMethod2
{
    abstract class Myclass
    {
       public abstract void AbstractMethod();
    }

    class MyInheritedClass : Myclass
    {
        public override void AbstractMethod()
        {
            Console.WriteLine("Abstract method implemented");
            Console.ReadKey();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyInheritedClass obj = new MyInheritedClass();
            obj.AbstractMethod();
        }
    }
}

In above AbstractMethod() is abstract method, which was implemented by derived class MyInheritedClass.

More Observations:
Abstract method must be public and starts with abstract keyword
If we not implement the abstract method in derived class we will get error message ''AbstractMethod2.MyInheritedClass' does not implement inherited abstract member 'AbstractMethod2.Myclass.AbstractMethod()'

Saturday, March 23, 2013

What is Object?

Object is a real world entity, object will be existing physically which means it will occupy memory where as Class is a logical unit.

If we want to use class methods or variables we need to create object, there is no other way to use class methods without creating object.

Ex:

 class A
    {
       public int sum(int a,int b)
        {
            return a + b;
        }
    }

class Program
    {
        static void Main(string[] args)
        {
            A obj = new A(); // Creating Object of Class A to access public methods of ClassA
            int sum = obj.sum(5, 4);
            Console.WriteLine(sum);
            Console.ReadKey();
           
        }
    }

In Class 'Program' used method 'sum' of another Class A by creating object of Class A

What is Class?

Class is a blue print or template which is having state and behavior and which supports objects of which own types.

Class must support oops concepts ie.
1.Abstraction
2.Encapsulation
3.Inheritance
4.Polymorphism

Wednesday, March 13, 2013

What is the difference between UserControl and Custom Control?

User Controls are easy to create where as Custom Controls requires extra effort

User Controls are used where layout is static where as custom controls are used in dynamic layouts

A User Control cannot be added to the toolbar where as Custom Control can be

A separate copy of User Control is required in every application that uses it where as since Custom Controls are shared in GAC, only single copy can be used by all applications.

What is Shared Assembly?

A shared assembly is kept in the GAC and can be used by one or more applications on a machine.

What is Private Assembly?

A private assembly is local to the installation directory of an application and is used only by that application

What is flat file?

A flat file as the name implies which can be read or written sequentially

What is Control?

A control is component that provides UI-Capability

What is meant by Business Logic?

It is the functionality which handles the exchange of information between DB and UI.