2/16/11

simple overriding concept (regular mistake)

I have presented a sample code snippet which will explain overriding mechanism and the common mistake that we do.

public class RegularOverridingMistake extends base {


    int i=100;
    public static void main(String a[]){
        base b=new RegularOverridingMistake();
        System.out.println("b.i--"+b.i);
        b.dip();
    }
    @Override
   void dip(){
        System.out.println("inside RegularOverridingMistake");
    }
}
class base{
    int i=5;
    base(){
     //   dip();  uncomment this line and look out the error
    }
    void dip(){
        System.out.println("inside base class");
    }

No comments:

Post a Comment

Popular Posts