Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what is object type casting? give some example with related?

Answers were Sorted based on User's Feedback



what is object type casting? give some example with related?..

Answer / ganesh

In java object typecasting one object reference can be type
cast into another object reference. The cast can be to its
own class type or to one of its subclass or superclass types
or interfaces. There are compile-time rules and runtime
rules for casting in java.
Consider an interface Vehicle, a super class Car and its
subclass Ford. The following example shows the automatic
conversion of object references handled by the compiler

interface Vehicle {
}
class Car implements Vehicle {
}

class Ford extends Car {
}

Let c be a variable of type Car class and f be of class Ford
and v be an vehicle interface reference. We can assign the
Ford reference to the Car variable:
I.e. we can do the following

'''Example 1
c = f; //Ok Compiles fine'''

Where c = new Car();
And, f = new Ford();
The compiler automatically handles the conversion
(assignment) since the types are compatible (sub class -
super class relationship), i.e., the type Car can hold the
type Ford since a Ford is a Car.

Is This Answer Correct ?    6 Yes 0 No

what is object type casting? give some example with related?..

Answer / aaratim

Object type casting is converting a object type into another
type. For example

Iterator ite = emplist.iterator();
while(ite.hasNext()){

Employee empObj = (Employee)ite.next();

}

Here ite.next returns instance of type Object, we need to
convert it to type Employee so this is called type casting.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is singletonlist in java?

0 Answers  


How many types of keywords are there?

0 Answers  


What are the types of statement? explain

1 Answers   SysBiz,


Is java pass by value or pass by reference?

0 Answers  


How can we achieve IPC in JAVA?

1 Answers   Wipro,


What is the importance of finally block in exception handling?

0 Answers  


What is difference between final and finally in java?

0 Answers   Cyient,


how to create multithreaded program? : Java thread

0 Answers  


What’s the difference between constructors and other methods?

0 Answers  


How can we achieve thread safety in java?

0 Answers  


write java code to print second max number in the array

12 Answers   Huawei, IBAB,


Can we sort a map in java?

0 Answers  


Categories