Overriding or Hiding.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Overriding or Hiding.

    Look at my code carefully.....

    [code=java]
    class Super
    {
    protected int a;
    }
    class Derived extends Super
    {
    protected int a; //Here Data Overriding or Data Hiding
    }
    [/code]

    Let's look at another example .....

    [code=java]
    class Super
    {
    public static void test()
    {
    //Some content
    }
    }
    class Derived extends Super
    {
    public static void test() //Here Method Overriding or Method Hiding
    {
    //Some content
    }
    }
    [/code]

    Plz explain .... Hiding and Overrinding for Method and Data ... for both.

    Kind regards,
    Dmjpro.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by dmjpro
    Look at my code carefully.....

    [code=java]
    class Super
    {
    protected int a;
    }
    class Derived extends Super
    {
    protected int a; //Here Data Overriding or Data Hiding
    }
    [/code]

    Let's look at another example .....

    [code=java]
    class Super
    {
    public static void test()
    {
    //Some content
    }
    }
    class Derived extends Super
    {
    public static void test() //Here Method Overriding or Method Hiding
    {
    //Some content
    }
    }
    [/code]

    Plz explain .... Hiding and Overrinding for Method and Data ... for both.

    Kind regards,
    Dmjpro.
    But we've talked about this before, dj. Remember the difference between a class variable and an instance variable.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by r035198x
      But we've talked about this before, dj. Remember the difference between a class variable and an instance variable.
      Ok.
      I know we have discussed before.
      But it would be better if u discuss again.
      Plz.

      Kind regards,
      Dmjpro.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by dmjpro
        Ok.
        I know we have discussed before.
        But it would be better if u discuss again.
        Plz.

        Kind regards,
        Dmjpro.
        You can't override a static

        Have a look at the examples in the JLS and decide ...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Only non-static methods can be overridden (if they're not final). Everything else
          can just be hidden. All methods can be overloaded but that is something completely
          different.

          kind regards,

          Jos

          Comment

          Working...