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 usage of Enumeration in C# Programming and is it good to use or not ?
What are virtual classes in c#?
What are access modifiers used for?
Can we inherit a class with private constructor in c#?
Are constructors inherited c#?
What is generic delegate in c#?
What does return do in unity?
Can you store different types in an array in c#?
What is meaning of type safety in c#?
How to prevent the error while updating ui control from another thread?
What is the difference between finalize() and dispose()?
What is object pool in .net?
Define c# i/o classes? List the commonly used classes?
what is difference between is and as operators in c#?
What is inner class in c#?