“Was ist var in Java?” Code-Antworten

Java -Variable

//this are the most common ones
int x = 5; 
String y = "hello";
System.out.println(x + y);
Alexperto

Was ist var in Java?

The var keyword was introduced in Java 10. 
Type inference is used in var keyword in which it detects automatically 
the datatype of a variable based on the surrounding context. 
The below examples explain where var is used and also where you can’t use it.
  

// Java program to explain that
// var can used to declare any datatype
  
class Demo1 {
  
    public static void main(String[] args)
    {
  
        // int
        var x = 100;
  
        // double
        var y = 1.90;
  
        // char
        var z = 'a';
  
        // string
        var p = "tanu";
  
        // boolean
        var q = false;
  
        // type inference is used in var keyword in which it
        // automatically detects the datatype of a variable
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
        System.out.println(p);
        System.out.println(q);
    }
}
SIKA T

Warum Var in Java verwenden?

improve the readability of code for other developers who read the code. 
In some situations
Good Gnu

Ähnliche Antworten wie “Was ist var in Java?”

Fragen ähnlich wie “Was ist var in Java?”

Weitere verwandte Antworten zu “Was ist var in Java?” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen