Skip to main content

All 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(...
How to's user avatar
  • 13
-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() { ...
NinaJava's user avatar
-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 ...
Austin's user avatar
  • 376
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; ...
Wax Yao's user avatar
  • 21
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 ...
DCR's user avatar
  • 15.4k
-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 ...
Star-lordX's user avatar
-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 ...
Bruce 's user avatar
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()");...
Shri's user avatar
  • 109
-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 ...
Илья Кротов's user avatar
-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() { ...
Plegeus's user avatar
  • 190
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 ...
F-H's user avatar
  • 943
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....
Jaydeep Ranipa's user avatar
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 ...
Kyuubi's user avatar
  • 1,228
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 ...
orangecola's user avatar
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 ...
M. Abdul Rehman's user avatar

15 30 50 per page
1
2 3 4 5
22