answersLogoWhite

0

What is type promotion of java?

Updated: 12/8/2022
User Avatar

Wiki User

12y ago

Best Answer
Type PromotionIn the aforementioned example System.out.println(3 + 4), the expression 3 + 4 is evaluated to 7 and then converted automatically, at runtime, to a String value which is whatprintln expects. This automatic conversion is a somewhat special case of type promotion.

Type promotion is an automatic type conversion from a "lesser" base type to a "greater" one or from any type to String via the toString() method.

A promotion from on base type to another may occur in an arithmetic expression:

Example:double x = 3.14 + 10; /* 10 is promoted to a double */ double y = 12; /* 12 is promoted to a double then assigned */

As mentioned earlier, type promotion occurs from a "lesser" type to a "greater" one where a type is "less" than another if it offers smaller precision. In our previous example, an int offers less precision than a double thus an int value can be promoted to a double as necessary. For the same reason a double cannot be promoted to an int. If an double is used where an int is expected, Java will generate an error:

Example:int z = 2.4; Compile-time error: possible loss of precision
User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is type promotion of java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What type of government in java?

Java has a Communist government.


How do you find out if your computer has java?

Open cmd and type java


How do you compile your java code?

save it into a .java file. then open command prompt and navigate to your java bin directory. then type CD then your java bin directory. then type this . javac ProgName.java


Where is the java directory?

Nowhere, Just Windows-r and type "JAVA"


What is the return type of finally method in java?

The final and finally keywords have no impact on the return type of a method in Java.


What is gini in Java language?

gini is the one type of extension of the java. gini is the advanced and advanced version of the java


Which type of language is java?

Java is truly object oriented programming language


Is float is a keyword in java?

yes, float is keyword and data type in java


Is button a data type in Java?

In Java, just about anything is defined as a class; a class is a data type, so yes.


Command use on how to run a java program?

You execute it the same way you would on any other OS. As long as you have the Java Runtime Environment installed and the "java" executable is in your path, from the command line you would simply run: java -cp /path/to/file/here com.some.class.to.run.Here


What is a variable type in Java?

int


What type of government does Java have?

Rupublc