-5

Can we override instance/static members in Java?
What could happen if we did?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Tejucb
  • 184
  • 4
  • possible dup of http://stackoverflow.com/questions/12589274/slight-confusion-regarding-overriding-where-variables-are-concerned – SSH Jun 06 '15 at 20:56
  • install any editor say eclipse - https://eclipse.org/downloads/packages/eclipse-ide-java-developers/lunasr2 and try it yourself!! Both of your doubts will be instantly clarified – spiderman Jun 06 '15 at 20:58

2 Answers2

0

Yes you can.

public class HelloWorld{

     public static void main(String []args){
        Child.hello();
     }

     static class Parent{
         public static int i = 0;

         public static void hello(){
             System.out.println("hello");
         }
     }

        static class Child extends Parent{
         public static int i = 1;

         public static void hello(){
             System.out.println("world");
         }
     }
}
Arthur Ceccotti
  • 380
  • 2
  • 6
-1

No we can't override instance/static fields in java. Also static methods can't be overridden.

Prudvinath
  • 15
  • 1
  • 5