Linked Questions
101 questions linked to/from Why doesn't Java allow overriding of static methods?
0 votes
0 answers
74 views
Call subclass's static method from parent class's non-static method [duplicate]
Suppose I have the following simple code: class A { protected int someMethod() { return staticMethod(); } private static int staticMethod() { return 10; } } class B ...
0 votes
0 answers
56 views
Why doesn't java provide implicit Method class' invoke? [duplicate]
Example from another stackoverflow thread link: public class RegularEmployee { private BigDecimal salary; public void setSalary(BigDecimal salary) { this.salary = salary; } ...
0 votes
0 answers
54 views
Generics, static Methods and Extension [duplicate]
I have an abstract Class: public abstract class BaseBean { public static String getTableName(){ return "base"; } } And I have several Classes extending BaseBean, for Example: ...
2 votes
0 answers
42 views
java inheritance - static fields and methods [duplicate]
I'm beginner to java.I just recently learned about inheritance between classes. I know that if I inherit from a class,I can use those fields and methods,and also the objects I create will have those. ...
1 vote
0 answers
38 views
Can we override static methods ? Why the output is so? [duplicate]
class Base { public static void display() { System.out.println("Static or class method from Base"); } public void print() { System.out.println("Non-static or Instance ...
-4 votes
1 answer
37 views
Should static method Override in java? [duplicate]
Is this method type hiding? How static method gets area in memory? public class Demo { public static final void main(String args[]) { try{ A a = new ...
0 votes
1 answer
29 views
why doesn't a static method allow for the parent class to be overridden? [duplicate]
This is the code that I'm dealing with: class Animal { public void hide() { System.out.println("The hide method in Animal."); } public void override() { System.out....
2096 votes
41 answers
697k views
Difference between static class and singleton pattern?
What real (i.e. practical) difference exists between a static class and a singleton pattern? Both can be invoked without instantiation, both provide only one "Instance" and neither of them is thread-...
685 votes
29 answers
358k views
Why can't static methods be abstract in Java?
The question is in Java why can't I define an abstract static method? for example abstract class foo { abstract void bar( ); // <-- this is ok abstract static void bar2(); //<-- this ...
117 votes
20 answers
310k views
Can I override and overload static methods in Java?
I'd like to know: Why can't static methods be overridden in Java? Can static methods be overloaded in Java?
224 votes
3 answers
143k views
Call static methods from regular ES6 class methods
What's the standard way to call static methods? I can think of using constructor or using the name of the class itself, I don't like the latter since it doesn't feel necessary. Is the former the ...
47 votes
7 answers
20k views
What are the key differences between OO in Smalltalk and Java?
What are the key differences between OO in Smalltalk and Java? Please note that I am a Java programmer trying to expand his horizons by exploring Smalltalk. Currently I know almost nothing about ...
74 votes
3 answers
49k views
Overriding a static method in python
Referring to the first answer about python's bound and unbound methods here, I have a question: class Test: def method_one(self): print "Called method_one" @staticmethod def ...
50 votes
5 answers
12k views
How come invoking a (static) method on a null reference doesn't throw NullPointerException?
I wrote this program in Java public class Why { public static void test() { System.out.println("Passed"); } public static void main(String[] args) { Why NULL = null; NULL.test(); ...
34 votes
9 answers
35k views
Why doesn't the compiler complain when I try to override a static method?
I know that we cannot override static methods in Java, but can someone explain the following code? class A { public static void a() { System.out.println("A.a()"); } } class B ...