What is type casting. Explain it with reference to classes.
Answer Posted / 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 View All Answers
Is arraylist generic in c#?
What is a Assembly?
What is difference between ienumerable and list in c#?
Can constructor be protected?
What are jump statements in c#?
What are the 2 kinds of data type conversions in c#?
What is an object and a class?
How big is a float?
How to Show Message box in Metro Style App?
How do I develop c# apps?
How do I stop my console from closing in c#?
What is using directive in c#?
What is the use of flag in c#?
What does the parsefloat function do?
What are extender provider components?