Showing posts with label OOPS. Show all posts
Showing posts with label OOPS. Show all posts

Tuesday, June 19, 2012

Difference between Class and Structure in .NET

1. Classes are reference types and structs are value types. Since classes are reference type, a class variable can be assigned null.But we cannot assign null to a struct variable, since structs are value type.

2. When you instantiate a class, it will be allocated on the heap.When you instantiate a struct, it gets created on the stack.

3. You will always be dealing with reference to an object ( instance ) of a class. But you will not be dealing with references to an instance of a struct ( but dealing directly with them).

4. When passing a class to a method, it is passed by reference. When passing a struct to a method, it’s passed by value instead of as a reference.

5. You cannot have instance Field initializers in structs. But classes can have
For eg:

class MyClass
{
   int myVar =10; // no syntax error.
   public void MyFun( )
   {
     // statements
   }
}

struct MyStruct
{
   int myVar = 10; // syntax error.
   public void MyFun( )
   {
     // statements
   }
}

6. Classes can have explicit parameterless constructors. But structs cannot have

7. Classes must be instantiated using the new operator. But structs can be

8. Classes support inheritance.But there is no inheritance for structs. (structs don’t support inheritance polymorphism)

9. Since struct does not support inheritance, access modifier of a member of a struct cannot be protected or protected internal.

10. A class is permitted to declare a destructor. But a struct is not

12. classes are used for complex and large set data. structs are simple to use.

Tuesday, June 5, 2012

Introduction OOPS (Object oriented programming system)

What is Oops?

Introduction
OOPs is the new concept of programming, parallel to Procedure oriented programming. It were intorduced in late 80's. It consider the programming simulated to real world objects.

Defination
Oops is Object oriented programming system. In the OOPS concept we devide our project in different modules(also called a classes) and then create a object for particular module and with the help of this object, we use the functionality of particular module. In OOP's concept we can't do anything without an Object. OOPS reduce the code of the program because of the extensive feature of Polymorphism. OOps have many properties such as DataHiding, Inheritence, Data Absraction, Data Encapsulation and many more.

Why we use oops concepts?
WE use OOPS because it supports polymorphism, inheritance, encapsulation.
Inheritance provide reusing the defined the code without rewriting them and as well we can write in them new fields and methods.
Encapsulation provide data hiding or data security. It also supports combining the variables and their methods in a single class. It also supports modification in coding without complexity. Because of Encapsulation, The Error can be detected easily.
Polymorphism at run time supports assigning a relative object at run time. It also supports method overriding that is same method name with different no of parameters or with parameters with different data types.