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 purpose of escape sequence?
Are c# generics the same as c++ templates?
Is unity object oriented?
what is the scope of anonymous type ?
State two different types of access modifiers.
What are fields in c#?
What is a Jagged Array in C#?
Why do we need delegates?
What is the base class for array types?
What is writeline?
Is c# easier than javascript?
What is a di class?
What is the difference between field and variable in c#?
What is .cs file in c#?
What is continue in c#?