class Shape{
void printS(Shape s){
if(s instanceof Shape) System.out.println("Shape class's obj");
else if(s instanceof rec) System.out.println("rec class's obj");
else if(s instanceof Circle) System.out.println("Circle class's obj");
}
}
class rec extends Shape{
}
class Circle extends Shape{
}
public class Test{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
Shape s1;
Shape s2;
Shape s3;
s1=new Shape();
s2=new rec();
s3=new Circle();
s2.printS(s2);
}
}
이 코드에서 printS 인자를 s1,s2,s3를 줄때 각각 다르게 출력하고싶은데 계속 첫번째 if문에서 true가 되는거같은데..
도와주세요ㅠㅠ
http://arer.tistory.com/52
String inputSt = scn.nsxtLine(); 스캐너 했으니, 값을 넣아줘야지.. 그리고, if(inputSt=="rsedfaasd){...} 이거 아닌가?
nextLine();
Shape s값을 if문으로 string 값과 비교 해야되겠네..
if( s.getClass() == Shape )