Sunday 29 December 2013

Different between delegate and event.

Delegate is function pointer. It is encapsulated function name.It is point to function with same signature of delegate.Multicast delegate is used for broadcast mechanism. One delegate is refer to multiple function and called all method simultaneously.
Event is used when some action happen when activity is perform in GUI. Activity is like button click,mouse hover ect. When activity is perform then associate action(delegate) is called and that delegate is called methods which are associated this delegate.
So, we can conclude that the delegate is encapsulate the methods and event is encapsulate the the delegate.

Saturday 28 December 2013

Why we used Delegate?

A delegate can be seen as a placeholder for a/some method(s). It is function pointer.
By defining a delegate, you are saying to the user of your class "Please feel free to put any method that match this signature here and it will be called each time my delegate is called".
Why we used delegate? for ansnwer read article this.

Wednesday 25 December 2013

What thing you have to remeber while dealing with static member?

A static member cannot be marked as override, virtual, or abstract.

Take this example

class  Base
    {
        public static virtual  void  fun()
        {
            Console.WriteLine("Base");
        }
     }
  class child : Base
    {
     public   override void fun()  //error: Static methods never be override
        {
            Console.WriteLine("child");
        }
       }

Monday 23 December 2013

What should be remember while dealing with Protected data member in child class?

I give one example .

class parent
   {
       protected int a;
   }
   class child : parent
   {
     
       void fun()
       {
           parent p = new parent();
           p.a = 10; //Error Cannot access protected member through parent object
           a = 10; //NO error .We can access protected member through inheritance hierarchy.
       }
   }

What thing you have to remember dealing with Static Constructor?



  •  Static constructor don't have any parameter.
  •  Static constructor don't have any access specifier because that constructor is never called from any other code so  that there is no meaning of access specifier.
  •  it is possible to define static constructor and zero parameter instance constructor defined in same class. although the parameter are identical, 
  •    there is no conflict because static constructor are called when class is loaded and instance constructor is loaded when instance is created.

Wednesday 18 December 2013

Exception Handling Example.

Question 1
Try
{
   return 5;
}
catch(Exception Ex)
{
    return 6;
}
finally
{
    return 7;
}

What is output of following code?
Ans: Error Control cannot leave the body of a finally clause.  You get above error message. But if you run this code in Java, You get output 7.

----------------------------------------------------------------------------------------------------
Question 2
Try
{
   return 5;
}
catch(Exception Ex)
{
 }
finally
{
 }
What is output of this code? 
Ans: 5. But You run this same code in Java it get the Error, Because finally  has not return statement.

Monday 16 December 2013

What things you have to remember while dealing with Static Constructor?

1. Static constructor never have any access specifier.

 class demo
    {
        public  static demo() // error
      {
      }
    }
2. You never decided when static constructor is called. but one thing you sure that static function is called before the firth call to any member of class. 

Saturday 14 December 2013

What is difference in function overriding in JAVA and .NET?

In Java Function overriding happen automatically while in .net you have to explicitly mention Virtual and override keyword. Without that both keyword overriding is not happening. For more Click here.  

Tuesday 10 December 2013

why we introduce function overloading in OPP?

this concept is used to reduce clumsy and laborious problem of programming style.

Why we introduce encapsulation in OOP? Differentiate Encapsulation, Data hiding, Data abstraction.

In procedural language, We create some public variable and that variable is access by any function. Suppose one function is used that variable but ideally that function should not access that variable. We get error at debug time and we correct that error.
Reduce to above problem, OOP introduce on concept is call encapsulation. In encapsulation we combine variables with functions (Which functions that used that variables). Now some other function can not able to access that variable directly and ours problem is solved now. 

Encapsulation is process of combining variable and function into one capsule (OOP term is called class) and access them using function (Like that both are one entity).

Data Hiding  is process of hiding data through Private access specifier and it can not accessible directly outside. If you want to access that variable then we write relevant function to access that variable.

Data Abstraction is process of hiding programming complexing from user. It can be implemented at class level, function level or package level. In class level data abstraction, you make some function are private that private function can not visible to user and some function as public which can be access by user. So hide unwanted complexity through private function is call Data Abstraction.

Monday 9 December 2013

When we used abstract class and when we used Interface?

Abstract class has some methods are abstract. Interface is fully abstract class and all method in interface are abstract.
When we used Abstract class?
Consider a case, There is abstract base class and two child classes are inherited that abstract method in base class. Suppose if you want to add one abstract method in base class then you have to define that method in both child class compulsory.so, you have to rewrite child code again. But it is possible that you write concrete method in abstract class and no need to change child class logic.

But, you thinks that same case for interface then, child class have to implement that method. Every time you add method in interface then you have to modify child at that time, and that thing is tedious in case of reusable component. Suppose you create on DLL(that content one interface) and both child class used that. and suppose you add on method in interface then you have modify child DLL.

When we used Interface?
Interface is one kind of contract. Contract means class which implement that interface have to define all method in that class. This thing is useful in case of on class have to implement some method compulsory. Example idisposable interface have dispose() abstract method and class which is implement IDisposable interface then class have define dispose() method.

means, Abstract class is useful in case of where you don't want to modify child class later. Interface is used where some contract(agreement) have to follow by child class.

Sunday 8 December 2013

What is rules of whitespace in C++?

You can not break Preprocessor statement to two. You must start to write with #include and follow by preprocessor name.
Also,String constant like "I am a student", can not break in separate line.

Friday 6 December 2013

Why Do We Need Object-Oriented Programming?

Object oriented programming is introduced because of so many limitation in procedural language,

Problems with Structured Programming is:


  • In procedural language, When program size is increase then is difficult to handle that program. Reasons behind is that  unrelated functions and data, provide a poor model of the real world. So program size is increase then function(module) is increase and it is difficult to manage whole program.
  • Second thing is Unrestricted Access of data. lets explain that, there are two type of data local and and global data.If I want to restrict access of my data through Local data then nobody can access that data from outside but I want to reuse that data in other function at that time I have to redeclare that data and  dependent code is every time.However, when two or more functions must access the same data—and this is true of the most important data in a program—then the data must be made global. then anybody can access that sensitive data.


so, We need one programming model that solve above problem and mapped with real world for easy to understanding purpose.

what is difference between CONST and Readonly ?

Readonly variable is declare at rum time (before exit of constructor). So, Readonly variable has different value depending on the constructor used at rumtime.

CONST varible is declare at compile time.

Mean, a const field is a compile-time constant, the Readonly field can be used for run-time constants.

What is Difference between Portable and Platform independent language?

In portable language, code is written in one system and  if you want to reuse that code on other system then you must be transfer that higher language code to other system and execute that code at other system. You can not run object file(law level file to ) of one system to other system. Example, C language is portable language. In C language, code is written on one system and you want to used that code to the other system then you transfer that C language code(higher level code) to other system and execute at there.Here you can not able  run Object file of one system to other system.

But, In platform independent code, code is written one system and you want to reuse that code to other system than you can do using low level compile code, transfer that code to other system and simple execute that code. Example, Java is Platform Independent language. Code is written on one system and you want to used that code to other system , simple transfer byte code file of one system to other and execute that other system.

Simple term, In portable language you must be execute higher language code to their system individually but In platform independent language, No need of execute higher language code to their system individually, Only low level file is sufficient for execution of code.