FAQ Database Discussion Community


What happens when a method is overridden in Java?

java,inheritance,method-overriding
When a predefined method in Java is overridden... Only the method signature must be same Both method signature and inheritance must be same What is the answer? 1 or 2 I know that when we override the method in superclass, the method signature should be the same. But what about...

Changing signature while Overriding in C++

c++,default-value,overriding,method-overriding,method-signature
I have a base class class Shape{ public: virtual int getArea()=0; } I want to change the signature while overriding like this: class Rectangle : class Shape{ public: int getArea(int someParameter = 0){ return 0; } } Is it possible somehow to achieve this, as I am using default value...

Java dynamic binding calling method of parent class

java,inheritance,method-overriding
Below is the code which I am trying to analyze. class Acc{ public void aMethod(List<Integer> A){ System.out.println(A.toString()); } } class Back extends Acc{ public void aMethod(String A){ System.out.println(A); } } Here if I invoke it as Acc a = new Back(); a.aMethod(list); But upon debugging the method of parent class...

Is there a convention for showing overridden methods in UML static class diagrams?

inheritance,uml,method-overriding
If class Human inherits some methods from superclass Mammal unchanged (such as laysEggs: () -> false) and overrides other methods (such as postsToStackOverflow : () -> true), is there any difference between how the different methods are indicated in portion of the UML static class diagram for Human? For example,...

Implementing a method of interface is overriding or not in java

java,interface,polymorphism,multiple-inheritance,method-overriding
I know this might be crazy but today one of my friend puzzled by asking when we implement an interface in java is it considered as method overriding. I told him it is not overriding as we are providing working(definition) of method first time when we implement any interface. To...

Polymorphism and overriding a method from a class template in C++ [duplicate]

c++,templates,polymorphism,method-overriding
This question already has an answer here: What is object slicing? 13 answers I would like to have a class template with basic implementations of my methods, and a set of subclasses that use the template class with particular types (double, int, char*) and override some subset of those...

Overriding methods in an ActiveSupport::Concern module which are defined by a class method in the same module

ruby-on-rails,ruby,activesupport,method-overriding,activesupport-concern
I have an ActiveSupport::Concern module which looks roughly like the following: module MyModel module Acceptance extend ActiveSupport::Concern included do enum status: [:declined, :accepted] end def declined! self.status = :declined # some extra logic self.save! end def accepted! self.status = :accepted # some extra logic self.save! end end end This is...

How do you pull specific objects from an arraylist?

java,inheritance,arraylist,polymorphism,method-overriding
I've made an Animal superclass, Shark and Whale subclasses. What would I use to print out just the Shark objects from this arraylist? Driver: import java.util.ArrayList; public class Creator { public static void main(String[] args){ ArrayList<Animal> obj = new ArrayList<Animal>(); obj.add(new Shark("James")); obj.add(new Shark("Mike")); obj.add(new Whale("Steve")); obj.add(new Whale("Tommy")); for (Animal...

C# always call a base method from the base class

c#,override,overriding,method-overriding
Lets assume that we have the following classes: class A { public virtual int Number { get { return 1; } } public int Foo(){ return Number; } } class B : A{ public override int Number { get { return 2; } } } As expected, if I'll call...

How to find out the proper overridden method in Eclipse

java,eclipse,method-overriding
I have one interface I1 which defines a method M1. Two other classes C1 and C2 are implementing I1 and over-rides M1. In another class C3 I have a reference to M1. Now how will I understand if M1 is referring to C1_M1 or C2_M1? P.S I can find it...

Order of including Helpers in ViewControllers

ruby,ruby-on-rails-4,method-overriding
In rails app, how are helpers included in viewcontrollers, and what's the order of includion(which helper is included first, second, so on)? Also, are all helpers available to views? If so, does the inclusion order same as the view's corresponding controller?...

Overriding an inner function of a method in python

python,python-2.6,method-overriding
That is a kind of best practices question. I have a class structure with some methods defined. In some cases I want to override a particular part of a method. First thought on that is splitting my method to more atomic pieces and override related parts like below. class myTest(object):...

Why can an abstract class force a concrete method to be overridden?

java,abstract-class,method-overriding
I use a library where an abstract class overrides a concrete method inherited from Object with an abstract method: public abstract class A { @Override public abstract boolean equals(Object obj); } To extend this class, I have to implement the equals method: public class B extends A { @Override public...

Concrete subclass that does not override abstract methods from abstract class

java,abstract-class,method-overriding
Say that I have two, abstract methods in an abstract base class: protected abstract void writeData(OutputStream stream); protected abstract void writeData(Writer writer); When I make an implementation, I have to override these methods so that when the data needs to be written, it knows how to do it. What I...

Why the output of following program is => BC::Display BC::Display BC::Display

c#,method-overriding
class BC { public virtual void Display() { System.Console.WriteLine("BC::Display"); } } class DC : BC { public virtual void Display() { System.Console.WriteLine("DC::Display"); } } class TC : DC { public virtual void Display() { System.Console.WriteLine("TC::Display"); } } class Program { public static void Main() { BC b; b = new...

Prestashop override Blocktopmenu function

php,prestashop,prestashop-1.6,method-overriding,function-overriding
I'm trying to override the generateCategoriesMenu function from blocktopmenu.php class BlocktopmenuOverride extends Blocktopmenu { public function generateCategoriesMenu($categories, $is_children = 0) { die( var_dump ('hello I am an override') ); } } I've set up this in the folder override/modules cleared the cache file class_index.php when I load my index page...

How do I force any subclasses of my class to always call a parent's implementation method they are overriding?

java,oop,inheritance,method-overriding
Let's say I have a class, which implements a method (addThings()). It serves as a foundation of a tree of subclasses: ParentClass { protected void addThings() { map.add(thing1); map.add(thing2); } } Now, let's say we implement a child class (which has Thing 3 as well) and Thing 3 also needs...