Méthode Java Short class shortValue() avec exemple
Méthode shortValue() de la classe courte
- méthode shortValue() est disponible dans le package java.lang.
- méthode shortValue() est utilisé pour renvoyer la valeur indiquée par cet objet Short converti en type short (par transtypage).
- méthode shortValue() 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 shortValue() ne lève pas d'exception au moment de la conversion de Short en short.
Syntaxe :
public short shortValue();
Paramètre(s) :
- Il n'accepte aucun paramètre.
Valeur renvoyée :
Le type de retour de cette méthode est short, elle retourne une valeur convertie (de type Short à short) représentée par cet objet Short.
Exemple :
// Java program to demonstrate the example // of shortValue() method of Short class public class ShortValueOfShortClass { public static void main(String[] args) { // Variables initialization short s1 = 10; short s2 = 20; // It returns short value denoted by this Short ob1 object // and converted to a short by calling ob1.shortValue() Short ob1 = new Short(s1); // Display ob1 result System.out.println("ob1.shortValue(): " + ob1.shortValue()); // It returns short value denoted by this Short ob2 object // and converted to a short by calling ob2.shortValue() Short ob2 = new Short(s2); // Display ob2 result System.out.println("ob2.shortValue(): " + ob2.shortValue()); } }
Sortie
ob1.shortValue(): 10 ob2.shortValue(): 20