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's the difference between WindowsDefaultLocation and WindowsDefaultBounds?
What is the default boolean value in c#?
What is the task perform by clr?
What are the 2 broad classifications of fields in c#?
What are the types of operator?
What are the fundamental principles of oo programming?
What can we do to handle multiple exceptions?
What are reflections in c#?
How to achieve polymorphism in c#?
What is nullable types in c#?
Define delegate in c#?
Why delegates are safe in c#?
What is difference between a constant and read-only in C#?
What is difference between array and list?
What can be done with c#?