Upcasting permits an object of a subclass type to be treated as an object of any superclass type.
Questions tagged [upcasting]
244 questions
0
votes
2 answers
up-casting a function to another of base class parameter
I want to up-cast a function whose parameter is of type Sub to another function type whose parameter is of type Base. (Sub extends Base)
std::function child_f = ...
std::function base_f =…

One Two Three
- 22,327
- 24
- 73
- 114
0
votes
1 answer
Upcasting in C (learning class inheritance)
Thanks for taking a look at my post, hopefully it will be relatively simple.
I am attempting to learn more about QP/C or QP/nano, but as part of understanding how it works I need to learn about OOP concepts in C. Which is detailed…

DisplayName001
- 253
- 2
- 3
- 8
0
votes
0 answers
c++ how to downcast from upcasted derived
I have a class named "package" which is the base of the derived "shader_package".
The package instances generally get exclusively generated in a function called load. It has a pointer to package as a return parameter. Therefore I can also return…

MoustacheSpy
- 743
- 1
- 6
- 27
0
votes
3 answers
Upcasting not to real base class
I'm a bit stuck with such awful problem of bad class hierarchy.
class A {...}; // abstract
class B : public A {...}; // abstract
class C {...}; // abstract
class a1 : public B, public C {...}; // indirect inheritance of A
class c1 : public A,…

Nikita Smirnov
- 813
- 8
- 17
0
votes
2 answers
Runtime upcasting failure from Thinking in Java
When running this code, why would it have runtime error?
The array is defined to hold Fruit, but how can I not give fruit to it after I initialized it with apple?
class Fruit{}
class Apple extends Fruit{}
class Jonathan extends Apple{}
class Orange…

Kun Peng
- 1
0
votes
0 answers
C++ avoid casting in derived class code for twin container/contained object design
I have twin base classes for a container class and contained object (in my case, for a generic graph class made of linked nodes, but I guess the question would stand in all cases where you want to derive from both a container class and a contained…

LMNCA
- 21
- 6
0
votes
2 answers
UpCasted field without access
How can I access a field in a UpCasted Object? I cannot use Console.WriteLine in order to print SuperPower property of a Guy object
namespace Test
{
class Guy
{
public int Power { get; set; }
}
class BigGuy : Guy
{
…

K.Zoyar
- 1
0
votes
4 answers
How to Access Parent Method using an Upcast object in JAVA?
I am new to Java and got a doubt regarding Upcasting and Down-Casting.
I have written the following code:
class Bike{
int speedlimit=90;
int bikeId = 123576;
Bike(){
System.out.println("inside Bike");} //end constructor
public void run(){…

Raj Sawant
- 1
- 2
0
votes
1 answer
Confusion regarding upcasting in Java
I am writing a networking code in java and It looks like following:
//Declaring the reference variable
HttpsURLConnection httpsURLConnection = null;
AuthHttpURLConnection authHttpURLConnection = null;
httpsURLConnection =…

java_doctor_101
- 3,287
- 4
- 46
- 78
0
votes
0 answers
Qt: Upcasting a signal's parameter to the slot
I have a signal that is emitted w/a parameter taken from a subclass, but in one slot implementation, I don't need a special handler for the subclass; just the parent class. I thought that connect() would upcast that parameter, but unfortunately, I…

Opux
- 702
- 1
- 10
- 30
0
votes
3 answers
How does Dynamic (run-time) polymorphism work in java? In other words how does the JVM know which methods to call?
Say you have an arrayList of objects ArrayList

Aleksandr Diamond
- 75
- 9
0
votes
2 answers
convert a integer to array of class type java
I take in a file which has a name (table) and the number of seats:
table1 6
table2 2
table3 4
I have an array of class Reservation which will take in the the name and the seat. I am having trouble converting the number of seats into the array. How…

bpham93
- 1
- 3
0
votes
0 answers
Is it possible to achieve run-time/compile-time polymorphism using downcasting?
I know that upcasting can be used to achieve run-time polymorphism in java. But I am curious about a similar possibility in case of downcasting. If polymorphism is possible in case of downcasting, then is it runtime or compiletime?
The below code is…

Daisy
- 31
- 4
0
votes
0 answers
Accessing members of class after Upcasting in Java
I am going through my notes(after 5-6 months) and I am unable to understand the output given by following code :
class Base
{
int x=20;
}
class Child extends Base
{
int x=50;
public static void main(String arg[])
{
Base b…

praggi
- 7
- 4
0
votes
1 answer
Swift: Inheritance in type parameters
I'm trying to cast an object of a class with a type parameter into an object of the same class with a more generic type parameter, as illustrated in the following Swift code:
class ParameterClassA {
}
class ParameterClassB: ParameterClassA…

David
- 437
- 1
- 4
- 15