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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Given a singly linked list, determine whether it contains a loop or not without using temporary space?

943


Differentiate between postfix and prefix operators in java.

1086


Can a constructor be private and how are this() and super() method used with constructor?

946


What is java Applet?

1044


Explain list interface?

918


What is return code?

959


What is preparedstatement in java?

994


Why is it important to initialize a variable?

944


What is bufferedwriter?

924


How to calculate the length of a singly linked list in java?

970


What is the base class of all exception classes?

1028


Mention some interfaces implemented by linked list in java.

984


What do you mean by formatting?

947


Explain Basics of OOP Language in java

994


Compare Mutex and Semaphore in java.

948