All Questions
Tagged with polymorphism overriding
325
questions
1
vote
1
answer
69
views
Java-dynamic-binding-problem-understanding
So, I have this problem (which I am guessing has something to do with dynamic binding) that I can not wrap my head around.
class A {
public int m(A p) {
return 12;
}
public int n(...
-6
votes
3
answers
115
views
Inheritance static methods [closed]
class Human {
private String name;
private int age;
public Human(String name, int age) {
this.name = name;
this.age = age;
}
public static void message() {
...
-2
votes
2
answers
64
views
Java polymorphism top level method is called
I have an inherited object in a java project and I am trying to call the overriden method in the child object. For some reason the parent version of the method is being called. It was my understanding ...
1
vote
1
answer
72
views
How to solve this method override and polymorphism problem that have different scope?
What will be the result of attempting to compile and run the following program?
public class Main {
public static void main(String[] args) {
A ref1 = new C();
B ref2 = (B) ref1;
...
0
votes
1
answer
69
views
Java overloading at compile time versus overriding at runtime and polymorphism
could someone explain what is meant when they say that overloading occurs at compile time whereas overriding occurs at runtime? My understanding is overloading occurs within a class where a method's ...
-2
votes
1
answer
42
views
Calling an overriden function in java
I'm writing a piece of code in which I need to call an overridden method of a parent class. This is easy to do in C++:
class A{
public:
void doPrint() {
print();
}
void ...
-4
votes
1
answer
434
views
Can the constructor of a child class update the values of variables in the parent class [duplicate]
question problem
In the question above var 1 is of type A but is calling the constructor of class B. So will passing the parameter 4 to the constructor update the "value" variable to 4 or ...
0
votes
0
answers
89
views
How to invoke the method in abstract class that has been overriden in the subclass in java?
In this below code:
interface I1 {
void m1();
}
interface I2 {
void m2();
}
abstract class A implements I1, I2 {
public void m1() {
System.out.println("Inside A: m1()");...
-2
votes
2
answers
51
views
C# overriding with child class
Lately I've stuck with some project. What I want to do?
I have some number of classes. Let's say something like that:
public class ActionEventArgs : EventArgs
{
public Creature actor;
}
public ...
-2
votes
1
answer
41
views
How to do propper object oriented programming in C++, late binding polymorphism? [duplicate]
I am trying to figure out how to do oop in C++...
The issue lies with overrides. Consider the following code:
#include <iostream>
class Base {
public:
Base() { }
virtual void print() { ...
3
votes
1
answer
902
views
How to enforce the override keyword when overriding abstract members?
The TypeScript compiler offers the noImplicitOverride setting that, if set to true, will enforce the override keyword when overriding a non-abstract member. For example:
abstract class A {
public ...
0
votes
1
answer
332
views
What is a best practice to initialize an object at runtime in a method in java?
I have a java method:
public void method(JSONObject jsonRequest, String token, int size) {
DataRequest request = new DataRequest(size);
request.from(jsonRequest);
if (StringUtils....
0
votes
2
answers
56
views
Scala argument upper type bounds and overriding
I am trying to understand and incorporate upper bound types with overriding in my system, but have not been able to achieve it without some ugly code. I have the following 2 traits:
trait MyId {
def ...
0
votes
1
answer
37
views
Does my code follows the principle of Polymorphism?
I'm a newbie to Java and I attempt to achieve Polymorphism with the requirements of using the following:
super keyword
overriding
having more than two classes
getting the user's input
using do-while
...
2
votes
2
answers
630
views
In a multi-level inheritance, does a grandchild require to implement a pure virtual method, if its parent has already implemented it?
class A {
public: virtual void start() = 0;
};
class B : public A {
public: void start();
};
class Ba : public B {
};
Do we need to redefine start() in Ba or the parent's B::start() would ...