JAVA공부하기 110

instanceof

 

//InstanceofTest1.java

class Element {int atomicNumber;}

class Point extends Element {int x, y;}

class InstanceofTest1 {

public static void main(String[] args) {

Element e = new Element();

Point p = new Point();

if (e instanceof Point) {

Stystem.out.println("First Test : I get your point !");

p = (point)e;

}

e = p;

if (e instanceof Point) {

System.out.println("Second Test : I get your point!");
p = (Point)e;

}

if (e instanceof Element) {

System.out.println("Third Test : I get your Element!");

p = (point)e;

}

}

}

 

 

 

 

+ Recent posts