I am not able to compile this code.
class Shape{
String Shape = "Shape";
int i;
Shape(){
System.out.println("Constructor Shape");
}
void draw(){
System.out.println("Draw Shape");
}
//String getCircleString(){return "None";}
}
class Circle extends Shape{
String sc = "Circle";
int ic;
Circle(){
System.out.println("Constructor Circle");
}
void draw(){
int ic1=0 ;
System.out.println("Draw Circle"+ic1);
}
public String getCircleString(){
return sc;
}
}
public class Geometry{
String g = "Geometry";
public static void main(String[] arg){
Shape s1 = new Circle();
s1.draw();
System.out.println("Variable Shape 3 sc from accessor "+ s1.getCircleString());
}
}
It gives me an error on the Print statement at s1.getCircleString() is not defined in the Shape class. But since I created it as a Circle should it not identify the function defined there.
If I create this function in Shape also then the error does not occur.
Guys can some one explain to me why this is happening as it is happening.
Thanks in advance.