c# - Please Tell me why does this code generates output 'Base Class'. Although Object is of Derived2 type and reference variable is also of same type -
c# - Please Tell me why does this code generates output 'Base Class'. Although Object is of Derived2 type and reference variable is also of same type -
namespace indiabixconsoleapplication { class baseclass { public void fun() { console.write("base class" + " "); } } class derived1: baseclass { new void fun() { console.write("derived1 class" + " "); } } class derived2: derived1 { new void fun() { console.write("derived2 class" + " "); } } class programme { public static void main(string[ ] args) { derived2 d = new derived2(); d.fun(); } } }
because derived methods not public
, selection external class (program
) has public baseclass.fun()
method. if create derived2.fun()
public give output expecting.
class methods (and properties/fields) private
default unless explicitly set public
(or protected
or internal
).
c# compiler-errors output
Comments
Post a Comment