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
Can main method be final?
What is the difference between ienumerable and enumerator?
Why is c# a good programming language?
So what makes your code really object-oriented #?
What method is used to sort the elements of the array in descending order?
what is c# command?
What is default parameter in c#?
What is asp net in c#?
Why singleton is sealed?
How to transpose multi-dimensional array?
What is a thread? What is multithreading?
Is exe is machine dependent?
What is the difference between a function and a method?
What does dbml mean?
What does using system mean in c#?