Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is type casting. Explain it with reference to classes.

Answers were Sorted based on User's Feedback



What is type casting. Explain it with reference to classes...

Answer / kiran vaidya

Type casting means converting some type to some another
type.

for example, there are three classes:

class Employee
{
//Logic for this class

}

class Manager:Employee
{
//Logic for this class

}

class Clerk:Employee
{
//Logic for this class

}


class Program
{
static void Main(string [] args)
{
Employee e=new Employee();


//Type casting
Manager m=(Manager)e;

//Or
Clerk c=(Clerk)e;

}

}

Is This Answer Correct ?    13 Yes 2 No

What is type casting. Explain it with reference to classes...

Answer / shubha

Type Casting is conversion of one type data to another type.

Ex:
public class Base{
//Your code goes here
}

public class Derived extends Base
{
//Inherit method or create your own code here
}

public class MainClass {
public static void main(String args[]){

Base b = new Derived(); //reference variable of Base class points object of Derived class
//Derived d = b; compile time error, requires casting
Derived d = (Derived) b; // type casting Base to Derived
//Here you call your base class methods as derived class methods
}
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Sharp Interview Questions

If a class is a ref type, how we can pass to a function.

1 Answers   Synechron,


What are sorted lists?

0 Answers  


Is type nullable c#?

0 Answers  


What is difference between value and reference types in C#.NET

0 Answers   BirlaSoft,


What is a void c#?

0 Answers  


How can we sort the elements of the array in descending order?

0 Answers  


What is Co- and Contra-Variance in C#?

0 Answers  


what is the main differnce between const,readonly and static

3 Answers   Beehive Systems, CDAC,


What are the features of c#?

0 Answers  


What?s the difference between the System.Array.CopyTo() and System.Array.Clone()?

3 Answers  


How can we set class to be inherited, but prevent the method from being over-ridden?

0 Answers  


how can include .netframeworl 2.0 in application setup

1 Answers  


Categories