Latest Questions tagged Overriding

Browse all latest questions tagged Overriding

93
Votes
Published 09 Sep, 2022
Java - Java "partial" override

When overriding a method in Java is it possible to call the "original" one. For example: public class A extends B{ @Override public void foo(){ System.out.println("yep"); // Then execute...

22
Votes
Published 12 Aug, 2022
Python - Python overload __init__

How do I overload __init__() in Python? I'm used to C/C++ where the compiler can see the difference in data type, but since there are no data types in Python, how can I make sure the third method gets...

62
Votes
Published 26 Aug, 2022
Java - can we have a main() in an interface and different implementations for main() in the classes that implement this interface?

I know that main() can be overloaded in a class with the compiler always taking the one with String[] args as arguments as the main method from where the execution starts. But is it possible to declar...

33
Votes
Published 14 Sep, 2022
Java - How can I override the toString method of an ArrayList in Java?

I would like to have my own implementation of the toString() method for an ArrayList in Java. However, I can't get it working even though I added my toString() like this to the class that contains the...

186
Votes
Published 10 Sep, 2022
Java - Is there a way to override class variables in Java?

class Dad { protected static String me = "dad"; public void printMe() { System.out.println(me); } } class Son extends Dad { protected static String me = "son"; } public...

122
Votes
Published 10 Sep, 2022
Java - Hibernate : How override an attribute from mapped super class

The generic entity, super class: @MappedSuperclass public abstract class GenericEntity { private Integer id; public Integer getId() {return id;} public void setId(Integer id) {this.id = i...

17
Votes
Published 09 Sep, 2022
Java - How can I get the implementation class name based on the interface object in Java

I want to get the implementation class name from my interface object — is there any way to do this? I know I can use instanceof to check the implementation object, but in my application there are nea...

71
Votes
Published 04 Sep, 2022
Java - How to quickly determine if a method is overridden in Java

There is a possible optimization I could apply to one of my methods, if I can determine that another method in the same class is not overridden. It is only a slight optimization, so reflection is out...

61
Votes
Published 02 Aug, 2022
Python - Access superclass' property setter in subclass

I have a SuperClass which defines a property and it's setter, like so: class A(object): def __init__(self): self._mode = None @property def mode(self): # to be overriden...

11
Votes
Published 02 Sep, 2022
Java - Override valueof() and toString() in Java enum

The values in my enum are words that need to have spaces in them, but enums can't have spaces in their values so it's all bunched up. I want to override toString() to add these spaces where I tell it...

82
Votes
Published 02 Sep, 2022
Java - Overriding the java equals() method - not working?

I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to tr...

52
Votes
Published 01 Sep, 2022
Java - method overriding in Java

How is method overriding implemented in Java? In C++ we have the concept of vtable.. how is this implemented internally in Java?

14
Votes
Published 01 Sep, 2022
Java - Why can’t we override a base class method with private extended class method?

class One { void foo() { } } class Two extends One { private void foo() { /* more code here */ } } Why is the above snippet of code wrong?

95
Votes
Published 01 Sep, 2022
Java - What does @AttributeOverride mean?

I'm currently coming (back) up to speed with EJB and while I was away it changed drastically (so far for the better). However, I've come across a concept that I am struggling with and would like to un...

89
Votes
Published 01 Sep, 2022
Java - Overriding a method in an instantiated Java object

I would like to override a method in an object that's handed to me by a factory that I have little control over. My specific problem is that I want to override the getInputStream and getOutputStream...