I have 2 drived calss and base class
class Base{
int a = 1000;
}
class Drivedone : Base{
public void GetInt(){ return a + 1; }
}
class Drivedtwo : base {
public void GetInt(){ return a + 2; }
}
void testFunction(Base argBase){
argBase.GetInt(); // this is Error
}
main(){
Base one = new Drivedone();
Base two = new Drivedtwo();
testFunction(one);//want print 1001
testFunction(two);//want print 1002
}
that was error. because GetInt didnt defined in Base class.
So i try this way.
class Base{
int a = 1000;
public void GetInt(){ return 0; }
}
class Drivedone : Base{
public new void GetInt(){ return a + 1; }
}
class Drivedtwo : base {
public new void GetInt(){ return a + 2; }
}
void testFunction(Base argBase){
argBase.GetInt(); // this is Error
}
main(){
Base one = new Drivedone();
Base two = new Drivedtwo();
testFunction(one);//want print 1001
testFunction(two);//want print 1002
}
this way i tried this way. define base function and with new keyword function in base class.
but this time. GetInt function always return 0;
how do i that??? please help me