Upcasting permits an object of a subclass type to be treated as an object of any superclass type.
Questions tagged [upcasting]
244 questions
-1
votes
1 answer
Why upcasted ab.a + ab.b produce result 1 and 1.0?
I don't get how we managed to invoke constructor without parameters in class A at all.
How upcasting works in this particular example? When we produce A ab = bb; what exactly ab refers to?
public class A {
public Integer a;
public Float…

cs_student
- 23
- 5
-1
votes
1 answer
how to call parent class mothod
I am studying run time polymorphism, I find one example like this
class Bike {
void run() {
System.out.println("running");
}
}
class Splender extends Bike {
void run(){
System.out.println("running safely with 60km");
…

dev_swat
- 1,264
- 1
- 12
- 26
-1
votes
3 answers
TextView textView = (TextView) findViewById(R.id.textView) is Upcasting or Downcasting?
I am totally confused as to below code does upcast or downcast.
If so how?
Is TextView a super class, I presume its a sub-type of View.
TextView textView = (TextView) findViewById(R.id.textView);

Yuvraj Mudaliar
- 375
- 5
- 15
-1
votes
2 answers
not getting the float answer
from tkinter import *
from datetime import datetime
import pickle
import os
##database will be with these mulas = dict{"name":["value","rate","left"]}
def _price_inputs():
filename = "datas.pk"
rupen = Tk()
rupen.title("Montessori…

HEalik Tamu
- 15
- 6
-1
votes
1 answer
Java: Disclosing protected value from object static Class using casting
Note: I found multiple information about disclose (get) value of protected fields or members of some class, my difference its a need to obtain of instanced objects...
Hi, I want to disclose information the previously instanced static Inner class…
user8086455
-1
votes
1 answer
java upcasting polymorphism issue
2 classes, A and B. class B inherits from class A.
What's wrong with the following code?
B b3 = (A)(new B());
Why isn't it a legal Upcasting?
It make sense. B instructor creates the B part of the whole object then A create its part and then it acts…

Edmond
- 43
- 1
- 10
-1
votes
2 answers
upcasting variable in derived class c++
How to change the type of a inherited variable in the derived class?
I have the following classes:
class Position;
class StonePosition;
class Position {
public:
Position() {}
};
class StonePosition : public Position {
int count;
public:
…

Nawy
- 13
- 1
- 5
-2
votes
1 answer
upcasting and downcasting in Java and Polymorphism
I'm confused why or when to use downcasting and upcasting and polymorphism.
Please tell me if I am correct or wrong. It would be a great help.
If we say this Gift gift = new Pen(); not only we can leverage the use of polymorphism (if subclass has…

Sourav Karjole
- 41
- 6
-2
votes
1 answer
Java inheritance: upcasting a subclass
I have read documentation and other questions, but there are cases of upcasting that really puzzle me.
I have this example, while the first 3 cases are quite straightforward after a bit of thinking, the last 4 leave me confused.
There is clearly…

rpadovani
- 7,101
- 2
- 31
- 50
-2
votes
2 answers
upcasting and downcasting c++
I was playing around with pointer to the base class, and I casted a rectangle pointer into a circle pointer and called the printradius() function from the rectangle! Could someone explain why this is allowed? Thanks.
#include
#include…

tao lin
- 7
- 1
-2
votes
2 answers
Why can't I use objects created on stack for upcasting?
Is this an upcast or not? If not, please describe why. Thanks in advance.
C++ code:
Base base;
Derived derived;
base = derived; // is this the upcast?

igorastvorov
- 47
- 7
-2
votes
3 answers
Upcasting pointers
I have a doubt with upcasting with pointers in C++.
I'm going to write an example of my problem:
class A {}
class B : public A {}
A* pA = new A();
B* pB = new B();
pA = pB; //fails
pA = dynamic_cast(pB); //fails
I don't know what I'm missing.…

Frion3L
- 1,502
- 4
- 24
- 34
-3
votes
1 answer
Why java upcasting causes overwritten girl method to be called?
I’m trying to understand upcasting with Java. I just created two classes Mom and Girl, with each having their own constructor (constructors have no parameters).
If I understand, Mom mom = new Girl() causes the instance created by new Girl to be cast…

Idash
- 55
- 8
-3
votes
1 answer
Is this upcasting or downcasting?
int main( )
{
Base *ptrBase = new Derived( 50, 60, 70 );
Derived *ptrDerived = ( Derived*)ptrBase;
ptrDerived->printRecord( );
delete ptrBase;
return 0;
}
user15023865
-4
votes
1 answer
Why does Person p = new Student() gives student type
Stupid question. So there is the code:
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public void Method()
{
Console.WriteLine("Hello, I'm person!");
}
}
class Student : Person
{
…

Sam
- 19
- 6