SlideShare a Scribd company logo
Type Casting 
Types of Data Types 
Primitive or Fundamental Data Types 
Referenced or Advanced Data Types 
Casting Primitive Data Type 
•Widening: Converting a lower data type into higher 
data type is called widening. 
•Narrowing: Converting a higher data type into lower 
data type is called narrowing 
byte short char int long float double
Type Casting… 
Widening in Primitive Data Types: 
char ch = ‘A’; 
int num = (int) ch; 
int x = 9500; 
float sal = (float) x; 
Note: Widening is safe because there will not be any loss 
of data. That is why, compiler does the casting internally 
and hence this is called “Implicit Casting”.
Type Casting… 
Narrowing in Primitive Data Types: 
int x = 66; 
char ch = (char) x; 
double d = 12.6789; 
int n = (int) d; 
Note: Narrowing is not safe because there will be loss of 
data. That is why, compiler forces the programmer to use 
cast operator and hence this is called “Explicit Casting”.
Type Casting… 
Casting Referenced Data Types: 
A class is a referenced data type. Converting a class type 
into another class type is also possible through casting. 
But the classes should have the same relationship 
between them by the way of inheritance. 
University 
College 
Department
Type Casting… 
Generalization: Generalization is a phenomenon where a 
sub class is promoted to a super class, and hence 
becomes more general. It needs widening or up-casting. 
Specialization: Specialization is a phenomenon where a 
super class is narrowed down to a sub class. It needs 
narrowing or down-casting.
Widening in referenced data type 
class One 
{ 
void show1() 
{ 
System.out.println("I am class one"); 
} 
} 
class Two extends One 
{ 
void show1() 
{ 
System.out.println("I am class Two"); 
} 
} 
class Test 
{ 
public static void main(String args[]) 
{ 
One o; 
o = (One) new Two(); 
o.show1(); 
} 
} 
Note: we are able to access show1() 
method of the super class. But in this 
case, it is not possible to call show2().

More Related Content

What's hot

Function in c
Function in cFunction in c
Function in c
savitamhaske
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
Hridoy Bepari
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Type casting
Type castingType casting
Type casting
Ruchika Sinha
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
Sachin Yadav
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 

What's hot (20)

Function in c
Function in cFunction in c
Function in c
 
This pointer
This pointerThis pointer
This pointer
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
File in C language
File in C languageFile in C language
File in C language
 
Strings
StringsStrings
Strings
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
Inline function
Inline functionInline function
Inline function
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Type casting
Type castingType casting
Type casting
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 

Viewers also liked

Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Type casting in ooabap
Type casting in ooabapType casting in ooabap
Type casting in ooabap
biswajit2015
 
Casting
CastingCasting
Casting
J.T.A.JONES
 
Casting
CastingCasting
Casting
Manoj Yadav
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
Sachin Sharma
 
Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
Casting and its types
Casting and its typesCasting and its types
Casting and its types
Waqas Ahmed
 

Viewers also liked (7)

Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Type casting in ooabap
Type casting in ooabapType casting in ooabap
Type casting in ooabap
 
Casting
CastingCasting
Casting
 
Casting
CastingCasting
Casting
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
 
Control statements
Control statementsControl statements
Control statements
 
Casting and its types
Casting and its typesCasting and its types
Casting and its types
 

Similar to Type casting

Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Unit 3
Unit 3Unit 3
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Pooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third Year
Dezyneecole
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
Sónia
 
Computer science_xii_2016
 Computer science_xii_2016 Computer science_xii_2016
Computer science_xii_2016
Ritika sahu
 
Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2
Karthik Srini B R
 
Unit 3 notes.pdf
Unit 3 notes.pdfUnit 3 notes.pdf
Unit 3 notes.pdf
Revathiparamanathan
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
Dev Chauhan
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_concept
Amit Gupta
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation
Ayush Gupta
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
Ananthu Mahesh
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
sotlsoc
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
SAMIR BHOGAYTA
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
Java unit2
Java unit2Java unit2
Java unit2
Abhishek Khune
 

Similar to Type casting (20)

Data types in java
Data types in javaData types in java
Data types in java
 
Unit 3
Unit 3Unit 3
Unit 3
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
 
Pooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third Year
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
 
Computer science_xii_2016
 Computer science_xii_2016 Computer science_xii_2016
Computer science_xii_2016
 
Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2
 
Unit 3 notes.pdf
Unit 3 notes.pdfUnit 3 notes.pdf
Unit 3 notes.pdf
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12BASIC CONCEPTS OF C++ CLASS 12
BASIC CONCEPTS OF C++ CLASS 12
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
implementing oop_concept
 implementing oop_concept implementing oop_concept
implementing oop_concept
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Java unit2
Java unit2Java unit2
Java unit2
 

More from simarsimmygrewal

Java file
Java fileJava file
Java file
simarsimmygrewal
 
C file
C fileC file
Java file
Java fileJava file
Java file
simarsimmygrewal
 
C file
C fileC file
C++ file
C++ fileC++ file
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
simarsimmygrewal
 
Handling inputs via io..continue
Handling inputs via io..continueHandling inputs via io..continue
Handling inputs via io..continue
simarsimmygrewal
 
Excception handling
Excception handlingExcception handling
Excception handling
simarsimmygrewal
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
simarsimmygrewal
 

More from simarsimmygrewal (9)

Java file
Java fileJava file
Java file
 
C file
C fileC file
C file
 
Java file
Java fileJava file
Java file
 
C file
C fileC file
C file
 
C++ file
C++ fileC++ file
C++ file
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
 
Handling inputs via io..continue
Handling inputs via io..continueHandling inputs via io..continue
Handling inputs via io..continue
 
Excception handling
Excception handlingExcception handling
Excception handling
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 

Recently uploaded

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 

Recently uploaded (20)

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 

Type casting

  • 1. Type Casting Types of Data Types Primitive or Fundamental Data Types Referenced or Advanced Data Types Casting Primitive Data Type •Widening: Converting a lower data type into higher data type is called widening. •Narrowing: Converting a higher data type into lower data type is called narrowing byte short char int long float double
  • 2. Type Casting… Widening in Primitive Data Types: char ch = ‘A’; int num = (int) ch; int x = 9500; float sal = (float) x; Note: Widening is safe because there will not be any loss of data. That is why, compiler does the casting internally and hence this is called “Implicit Casting”.
  • 3. Type Casting… Narrowing in Primitive Data Types: int x = 66; char ch = (char) x; double d = 12.6789; int n = (int) d; Note: Narrowing is not safe because there will be loss of data. That is why, compiler forces the programmer to use cast operator and hence this is called “Explicit Casting”.
  • 4. Type Casting… Casting Referenced Data Types: A class is a referenced data type. Converting a class type into another class type is also possible through casting. But the classes should have the same relationship between them by the way of inheritance. University College Department
  • 5. Type Casting… Generalization: Generalization is a phenomenon where a sub class is promoted to a super class, and hence becomes more general. It needs widening or up-casting. Specialization: Specialization is a phenomenon where a super class is narrowed down to a sub class. It needs narrowing or down-casting.
  • 6. Widening in referenced data type class One { void show1() { System.out.println("I am class one"); } } class Two extends One { void show1() { System.out.println("I am class Two"); } } class Test { public static void main(String args[]) { One o; o = (One) new Two(); o.show1(); } } Note: we are able to access show1() method of the super class. But in this case, it is not possible to call show2().