Posts

Showing posts with the label OOPS

Differance between Value Type and Referance Type

Value Type: 1) Stored in stack. 2) Access directly. 3) Life time determine by lifetime of variable that contain them. 4) e.g. All numeric data type, Boolean, char, Date, Structure, enumerations. Reference Type: 1) Stored in heap. 2) Access through references. 3) Lifetime is managed by .net framework. 4) e.g. All arrays, String, Class types, Delegate. Note: Object is not any kind of type. You can create object of structure as well as Class Are not type: Namespaces, Modules, Events, properties, procedures, variables, constants ,& fields.

Differance between Dataset and Datareader

Dataset 1) Read/write access to data. 2) Disconnected architecture. 3) Include multiple table from different database. 4) Bind to multiple controls. 5) forward and backward scanning of data. 6) supported by visual studio .net tool. 7) you can set relation between tables. DataReader 1) Read only 2) Connected architecture. 3) Include 1 table from 1 database only. 4) Bind to one control only. 5) fast forward only. 6) Manually coded. 7) No relations.

Differance between Strucutre and Class

Structure: 1) Value type stored in stack. 2) Inheritance is not possible in structure. 3) do not require constructor. 4) objects are not terminated by GC. 5) members can not be protected. Class: 1) Reference type stored in heap. 2) Inheritance is possible. 3) Contain constructor. 4) object is terminated by GC. 3) Member can be any type.

Differeance between Interface and Abstract Class

Interface: 1) Define a Contract. 2) can inherit only interfaces. 3) don't have constructor and distructor. 4) don't have concrete methods. 5) Inheritable by Structure. 6) Multiple inheritance is possible using Interface. 7) All members are Public by default. Abstract Class: 1) Can't be initiated, partially implemented. 2) Can inherit classes & Interfaces. 3) Can have Constructor & Distructor. 4) Some methods can be concrete. 5) Not inheritable by structure. 6) Multiple inheritance not possible. 7) Members can have many modifiers.

Differance between Overloading and Overriding

Overloading: 1) Same name in same/derived class but with different/type of parameter. 2) Compiletime polymorphism. 3) Having Different signature. Overriding: 1) we need to provide different implementation than base class. 2) Runtime Polymorphism. 3) Having same signature.

Differance between Const and Readonly

Const 1) Value evaluated at compile time 2) can't be static. 3) Initialize at declaration only. e.g. const int a = 100 Readonly 1) Value evaluated at runtime. 2) Can be static. 3) can initialize at declaration or in constructor. e.g. public readonly int doc = 5; public program() { doc = 5; }

Method Overloading Example

public class AddingNumbers { /// /// Method Overloading /// /// Example : Console.WriteLine() & System.Math.Sign() /// overloading a method when you for some reason need a couple of methods that take different perameters, /// but conceptually do the same thing. /// /// /// /// public int Add(int a, int b) { return a + b; } public int Add(int a, int b, int c) { return a + b + c; } // Error'OOPS_Overloading.Program.AddingNumbers' already defines a member called 'Add' with the same parameter types C:\Documents and Settings\milindm\My Documents\Visual Studio 2005\Projects\OOPS_Overloading\OOPS_Overloading\Program.cs 21 27 OOPS_Overloading /* public string Add(int a, int b, int c) { return Convert.ToString...

Interface Example

Interface Example interface IPoint { // Property signatures: int x { get; set;} int y { get; set;} // method signature void print_points(); } class Point : IPoint { // Fields: private int _x; private int _y; // Constructor: public Point(int x, int y) { _x = x; _y = y; } // Property Implementation: public int x { get { return _x; } set { _x = value; } } public int y { get { return _y; } set { _y = value; } } // Method Implementation public void print_points() { Console.WriteLine("{0} {1}", _x, _y); } } class Program { /// /// Interface /// /// -...

Abstract Example

abstract class BaseClass // Abstract class { protected int _x = 100; protected int _y = 150; public abstract void AbstractMethod(); // Abstract method public abstract int X { get; } public abstract int Y { get; } } class Program : BaseClass { /// /// Abstract Class /// /// Use the abstract modifier in a method or property declaration to indicate that the method /// or property does not contain implementation. /// Use the abstract modifier in a class declaration to indicate that a class is intended only /// to be a base class of other classes. /// The abstract modifier can be used with classes, methods, properties, indexers, and events. /// /// -An abstract class cannot be instantiated. /// -An abstract class class cannot be inherited. /// -An abstract class may contain abstract methods and accessors. ...

Static Constructor Example

/// /// A static constructor is used to initialize any static data, or to perform a particular action that /// needs performed once only. It is called automatically before the first instance is created or any /// static members are referenced. /// /// -A static constructor does not take access modifiers or have parameters. /// -A static constructor is called automatically to initialize the class before the first instance is created /// or any static members are referenced. /// -A static constructor cannot be called directly. /// -The user has no control on when the static constructor is executed in the program. /// -A typical use of static constructors is when the class is using a log file and the constructor is used /// to write entries to this file. /// -Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor /// can call the LoadLibrary ...

Sealed Class Example

/// /// Sealed Class /// /// You can Initiate the class /// You can not Inherit the class : class B : A { } /// Structs are implicitly sealed; therefore, they cannot be inherited. /// System.Threading.Thread /// /// sealed class A { public A() { } public void Test1() { } public static void Test2() { } } /*//Error : 'OOPS_Sealed.Program.B': cannot derive from sealed type 'OOPS_Sealed.Program.A' class B : A { }*/ static void Main(string[] args) { A obj = new A(); A.Test2(); }

Go through Static class example

/// /// Static Class /// /// You can not Initiate : A obj = new A(); /// You can not Inherited : class B : A { } /// All the members in Static class are static /// They cannot contain Instance Constructors : public A { } /// /// static class A { /* Error 'test': cannot declare instance members in a static class public void test() { } */ public static void test() { } } /*Error cannot derive from static class 'OOPS_Concept.Program.A' class B : A { } */ static void Main(string[] args) { /* Error 1 Cannot declare variable of static type 'OOPS_Concept.Program.A' Error 2 Cannot create an instance of the static class 'OOPS_Concept.Program.A' ...

oops questions

OOPs questions Inheritance The process of sub-classing a class to extend its functionality is called Inheritance.It provides idea of reusability. Order of Constructor execution in Inheritance constructors are called in the order from the top to the bottom (parent to child class) in inheritance hierarchy. Order of Destructor execution in Inheritance The destructors are called in the reverse order, i.e., from the bottom to the top (child to parent class) in the inheritance hierarchy. What are Sealed Classes in C#? The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class) Can you prevent your class from being inherited by another class? Yes. The keyword “sealed” will prevent the class from being inherited. Can you allow a class to be inherited, but prevent the method from being over-ridden? Yes. Just leave the class publi...

Interview Questions c#

Interview Questions C# What’s the implicit name of the parameter that gets passed into the class’ set method? Value, and its datatype depends on whatever variable we’re changing. How do you inherit from a class in C#? Place a colon and then the name of the base class. Notice that it’s double colon in C++. Does C# support multiple inheritance? No, use interfaces instead. When you inherit a protected class-level variable, who is it available to? Classes in the same namespace. Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. Describe the accessibility modifier protected internal. It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in). C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no par...