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 tpl in c#?
Explain deadlock?
What are the 4 pillars of any object oriented programming language?
Why is ienumerable used?
What is dbcontext c#?
What are synchronous and asynchronous operations?
What is anonymous methods in c#?
How do you create dlls in .NET
Difference between type constructor and instance constructor? What is static constructor, when it will be fired? And what is its use?
What is difference between class and interface in c#?
If I return out of a try/finally in c#, does the code in the finally-clause run?
How to move to a state-related codebase?
Explain the accessibility modifier protected internal?
What is a web service in c#?
Is comparator a functional interface?