What is the result(instanceof operator)? : Questions « Operators « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Operators » Questions 
2.13.19.What is the result(instanceof operator)?
interface Vessel {
}

interface Toy {
}

class Boat implements Vessel {
}

class Speedboat extends Boat implements Toy {
}


public class MainClass {
  public static void main(String[] args) {
    String s = "0";
    Boat b = new Boat();
    Boat b2 = new Speedboat();
    Speedboat s2 = new Speedboat();
    if ((instanceof Vessel&& (b2 instanceof Toy))
      s += "1";
    if ((s2 instanceof Vessel&& (s2 instanceof Toy))
      s += "2";
    System.out.println(s);
  }
}
2.13.Questions
2.13.1.May a class reference appear on the left-hand side of an instanceof operator?
2.13.2.Answer: left-hand side of instanceof operator
2.13.3.May a class appear on the left-hand side of an instanceof operator?
2.13.4.Answer: left-hand side instanceof operator
2.13.5.What is the result(tenary operator)?
2.13.6.Answer: tenary operator
2.13.7.What is the result(command line arguments)?
2.13.8.Answer: command line arguments
2.13.9.What is the result(string Concatenation)?
2.13.10.Answer: string Concatenation
2.13.11.What is the result(Multidimensional arrays)?
2.13.12.Answer: Multidimensional arrays
2.13.13.What is the result(for-each iteration)?
2.13.14.Answer: for-each iteration
2.13.15.What is the output(boolean and logical operators)?
2.13.16.Answer: boolean and logical operators
2.13.17.What is the output(bit masking)?
2.13.18.Answer: bit masking
2.13.19.What is the result(instanceof operator)?
2.13.20.Answer: instanceof operator
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.