- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are up-casting and down-casting in Java?
Typecasting is converting one data type to another.
Up-casting − Converting a subclass type to a superclass type is known as up casting.
Example
class Super { void Sample() { System.out.println("method of super class"); } } public class Sub extends Super { void Sample() { System.out.println("method of sub class"); } public static void main(String args[]) { Super obj =(Super) new Sub(); obj.Sample(); } }
Down-casting − Converting a superclass type to a subclass type is known as downcasting.
Example
class Super { void Sample() { System.out.println("method of super class"); } } public class Sub extends Super { void Sample() { System.out.println("method of sub class"); } public static void main(String args[]) { Super obj = new Sub(); Sub sub = (Sub) obj; sub.Sample(); } }
- Related Articles
- What is the difference between up-casting and down-casting in Java?
- How is down-casting possible in Java?
- What are the differences between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java?
- What is a casting expression in Java?
- Java Type Casting Examples
- What is Casting operators in C++?
- What is Type casting in C#?
- Type casting in JavaScript.
- Casting in Rust Programming
- Difference between Casting and Forging
- Type Casting operators in C++
- Explicit type casting operator in C++
- Explicit Type Casting in Python Language
- const_cast in C++ - Type casting operators
- Difference Between Type casting and Type Conversion

Advertisements