Java - Interview Questions and Answers for 'Casting' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Casting' - 6 question(s) found - Order By Newest

 Q1. What is Generalization and Specialization in terms of casting ?Core Java
Admin
info@buggybread.com
Ans. Generalization or UpCasting is a phenomenon where a sub class is prompted to a super class, and hence becomes more general. Generalization needs widening or up-casting. Specialization or DownCasting is a phenomenon where a super class is narrowed down to a sub class. Specialization needs narrowing or down-casting.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   casting   up casting   downcasting   generalization   specialization     Tata Consultancy (TCS)  VirtusaPolaris


  Q2. What is casting?Core Java
Anonymous
Ans. There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   casting   basic interview question     Mindtree  HCL Technologies  Wipro  Tata Consultancy (TCS)  Infosys  KPMG      basic        frequent


 Q3. When do you get ClassCastException?
Anonymous
Ans. As we only downcast class in the hierarchy, The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   class casting   classcastexception   exception   error      intermediate        frequent

Try 2 Question(s) Test


 Q4. Difference between implicit and explicit type casting ?
Anonymous
Ans. An explicit conversion is where you use some syntax to tell the program to do a conversion whereas in case of implicit type casting you need not provide the data type.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   casting


 Q5. What is the use of upcasting in Java ?Core Java2017-06-23 12:54:52

Ans. Interfacing

Car extends Vehicle

Car car = new Car();

// now you need to call an API changeTires() which can change tires for all Vehicle Types and accepts argument of type Vehicle and hence you will have to upcast it

changeTires((Vehicle)car);


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     upcasting


 Q6. Which of the following can throw ClassCastException ?Core Java
a. UpCasting
b. DownCasting
c. Casting to incompatible data type
d. Casting to Strings

Ans.b. DownCasting



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: