I don't know what to name this topic
class X
{
public:
double A(double x)
{
return x*x;
}
double B(double x)
{
return A(x)/2;
}
};
class Y :public X
{
public:
double A(double x)
{
return x*x*x;
}
};
void main()
{
Y y;
cout<<y.B(3);
}
this gives 4.5
but in java
public class X
{
public:
double A(double x)
{
return x*x;
}
double B(double x)
{
return A(x)/2;
}
}
public class Y extends X
{
public:
double A(double x)
{
return x*x*x;
}
}
public class App
{
public static void main(String s[])
{
Y y=new Y();
System.out.println(y.B(3));
}
}
this gives 13.5
Why
Then what is the use of interface in java?