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
What is the difference between do and while loop?
what is scope of a protected internal member variable of a c# class
What is a partial class. Give an example?
What is data annotation in c#?
Is vs as c#?
Is 0 an unsigned integer?
How do I know if executenonquery is successful c#?
How does array sort work?
What is a static field?
What is mvc pattern in c#?
Where is c# compiler located?
What is namespace c#?
How long will it take to learn c sharp?
What is the meaning of extention?
If a.equals(b) is true then a.gethashcode & b.gethashcode must always return same hash code.