Skip to main content
deleted 80 characters in body
Source Link
Tim Biegeleisen
  • 526k
  • 32
  • 324
  • 399

I have two class as following:

public class Car   {   public static void print()  {   System.out.println(getWord());   }   public static String getWord()  {   return "CAR";   } } public class BMW extends Car   {   public static String getWord()  {   return "BMW";   } } // main method public static void main(String args[])   {   BMW.print(); } 

After I run above sample, this output is printed:

CAR

My question is: Why is the method getWord() not overriden?

I have two class as following:

public class Car  {   public static void print()  {   System.out.println(getWord());   }   public static String getWord()  {   return "CAR";   } } public class BMW extends Car  {   public static String getWord()  {   return "BMW";   } } // main method public static void main(String args[])  { BMW.print(); } 

After I run above sample, this output is printed:

CAR

My question is: Why is the method getWord() not overriden?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) {   BMW.print(); } 

After I run above sample, this output is printed:

CAR

My question is: Why is the method getWord() not overriden?

Reformulated for better readibility
Source Link
thaussma
  • 9.9k
  • 5
  • 46
  • 46

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

After I run above sample, this output is printprinted:

CAR

My question is: Why is notthe method getWord() methodnot overriden?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

After I run above sample, this output is print:

CAR

My question is: Why is not getWord() method overriden?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

After I run above sample, this output is printed:

CAR

My question is: Why is the method getWord() not overriden?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

afterAfter I run above sample, print CAR inthis output. is print:

CAR

My question is: Why method hidingis not support inheritance in my programgetWord() method overriden?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

after run above sample, print CAR in output.

My question is: Why method hiding not support inheritance in my program?

I have two class as following:

public class Car { public static void print() { System.out.println(getWord()); } public static String getWord() { return "CAR"; } } public class BMW extends Car { public static String getWord() { return "BMW"; } } // main method public static void main(String args[]) { BMW.print(); } 

After I run above sample, this output is print:

CAR

My question is: Why is not getWord() method overriden?

Source Link
Sam
  • 7k
  • 9
  • 58
  • 95
Loading