“Java instanceof mot-clé” Réponses codées

Instance java

class Main {

  public static void main(String[] args) {

    // create a variable of string type
    String name = "Programiz";
    
    // checks if name is instance of String
    boolean result1 = name instanceof String;
    System.out.println("name is an instance of String: " + result1);

    // create an object of Main
    Main obj = new Main();

    // checks if obj is an instance of Main
    boolean result2 = obj instanceof Main;
    System.out.println("obj is an instance of Main: " + result2);
  }
}
SAMER SAEID

Opérateur Java Instance Of

class Main {
  public static void main(String[] args) {

    String str = "Programiz";
    boolean result;

    // checks if str is an instance of
    // the String class
    result = str instanceof String;
    System.out.println("Is str an object of String? " + result);
  }
}
rono schngr

Java instanceof mot-clé

public class Main {
  public static void main(String[] args) {
    Main myObj = new Main();
    System.out.println(myObj instanceof Main); // returns true
  }
}
naly moslih

Instance de Java

@Test
public void givenWhenInstanceIsCorrect_thenReturnTrue() {
    Ring ring = new Ring();
    Assert.assertTrue(ring instanceof Round);
}
Nguyen Nguyen

Opérateur Java Instance Of

objectName instanceOf className;
SAMER SAEID

Réponses similaires à “Java instanceof mot-clé”

Questions similaires à “Java instanceof mot-clé”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code