Méthode Java Short class floatValue() avec exemple
Méthode courte de la classe floatValue()
- méthode floatValue() est disponible dans le package java.lang.
- méthode floatValue() est utilisé pour renvoyer la valeur indiquée par cet objet Short converti en type float (par casting).
- méthode floatValue() est une méthode non statique, elle est accessible uniquement avec l'objet de classe et si nous essayons d'accéder à la méthode avec le nom de la classe, nous obtiendrons une erreur.
- méthode floatValue() ne lève pas d'exception au moment de la conversion de Short en float.
Syntaxe :
public float floatValue();
Paramètre(s) :
- Il n'accepte aucun paramètre.
Valeur renvoyée :
Le type de retour de cette méthode est float, elle retourne une valeur convertie (de type Short à float) représentée par cet objet Short.
Exemple :
// Java program to demonstrate the example // of floatValue() method of Short class public class FloatValueOfShortClass { public static void main(String[] args) { // Variables initialization short s1 = 30; short s2 = 40;; // It returns an short value denoted by this Short ob1 object // and converted to a float by calling ob1.floatValue() Short ob1 = new Short(s1); // Display ob1 result System.out.println("ob1.floatValue(): " + ob1.floatValue()); // It returns an short value denoted by this Short ob2 object // and converted to a float by calling ob2.floatValue() Short ob2 = new Short(s2); // Display ob2 result System.out.println("ob2.floatValue(): " + ob2.floatValue()); } }
Sortie
ob1.floatValue(): 30.0 ob2.floatValue(): 40.0