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
0 answers
Question about typecasting objects and accessing a method
I'm a bit confused about the syntax of typecasting and the creation of objects. Here I have a code of
class OverridingTest{
public static void main(String [] args){
Dog dog = new Hound();
((Hound)dog).sniff();
}
}
class Dog{
public…

Zidane101
- 13
- 3
0
votes
2 answers
C++ Upcasting from Multiple Inheritance; the source is not polymorphic
I am a newbiee in C++.
I have two pure abstract classes (like interfaces), and I derive a Class from these two pure abstracts classes.
In a case, I need to upcast the derived class pointer to one of the base abstract classes.
First of all, is…

muratcakmak
- 325
- 2
- 14
0
votes
1 answer
Better expression for down-casting and up-casting?
If you know the difference between upcasting and downcasting, then you
still can get it wrong because you can only make an educated guess about how
the inventor of these names paints his inheritance trees.
In computing science trees grow into the…

Patrick Fromberg
- 1,313
- 11
- 37
0
votes
2 answers
Why does the sublcass respond when upcasted?
interface Readable {
public void printTitle();
}
class WebText implements Readable {
public String title;
public void printTitle(){
System.out.println("This Webpage title is "+ title);
}
public void setTitle(String…

Ben Naylor
- 29
- 6
0
votes
2 answers
Does an object lose its attributes value after Upcasting and then Downcasting?
I have upcasted Model2 instance in the following code to Object class and then downcasted back to the class - Model2 in the test method of Model1 class. But thenUov its attribute value after downcasting is showing null. Is this expected for the…

user93726
- 683
- 1
- 9
- 22
0
votes
1 answer
C# Interface Implicit Promotion similar to unboxing, using a known hierarchical pattern of Interfaces:
Weird question here - something that's come up, due to the environment I'm working within.
A bit of a preface:
I am going to abuse well-known abstractions from the Taxonomic rank to describe the situation I'm stuck with - by design decisions which…

Matthew K. Crandall
- 86
- 1
- 7
0
votes
1 answer
In java, does repetition of downcasting and upcasting erases data inside subclass?
I realize that upcasting converts subclass to superclass while downcasting does so in opposite way. However, assuming there are different numbers of data types for subclass and superclass, does conversion from subclass->superclass->subclass makes…

Nathan Lee
- 75
- 1
- 3
- 10
0
votes
4 answers
Why downcasting throws ClassCastException in this case?
I have 2 packages: controller and federation. Controller just contains controller class with main method, but federation contains 2 classes, Shuttle (parent class) and MiniShuttle (child class). Upcasting works like a charm, but when I try to…

Amar Kalabić
- 888
- 4
- 15
- 33
0
votes
8 answers
How can I override a virtual method, but still invoke the base class version in C#
I have a simple class hierarchy where I have a virtual method that is overriden. But at certain callsites I want to call the base class version of this method rather than the virtual method.
For example:
public class A {
public virtual void…

Kang Su
- 701
- 2
- 10
- 19
0
votes
1 answer
Why up-casting to Webdriver is done instead of RemoteWebdriver while working with any browser driver in Selenium?
RemoteWebdriver implements Webdriver interface then why don't we up-cast to RemoteWebdriver instead of Webdriver while creating object of any browser driver?

user2044296
- 504
- 1
- 7
- 18
0
votes
1 answer
Assigning base class to derived and vice versa in C++ and difference between static and dynamic objects
Considering
class base { }
And
class derived: public base {}
What's the difference between:
FIRST CASE:
int main() {
base b;
derived d;
}
And
SECOND CASE:
int main() {
base *b;
derived *d;
}
And if we downcast and upcast in the second…

Amine
- 1,396
- 4
- 15
- 32
0
votes
2 answers
how is this upcasting demo working?
I have created an upcasting demo and i don't understand how this code is working or i can more specifically say why is constructor of base class also called while the dispatching is done with the Derived class.And there is even not a call to the…

Nnnnn
- 133
- 3
- 15
0
votes
3 answers
Why can't we use new ClassName() like we use in java,instead of using new ClassName?
I have wondered that both c++ and java using oops concepts but the syntaxes are quite different.
I found that java uses new ClassName() to get a reference to the heap but getting the same reference to the heap why the c++ uses new ClassName.
…

Ganesh Chowdhary Sadanala
- 1,160
- 1
- 12
- 23
0
votes
1 answer
HSSFWorkbook not upcast to Workbook
why not unable to compile :
POIFSFileSystem fs = new POIFSFileSystem(in);
Workbook wb=new HSSFWorkbook(fs);
the complier tell me "wb" should be HSSFWorkbook Object.

udevil
- 1
- 1
0
votes
0 answers
What exactly is an upcast? My CS111 instructor told me that I have an upcast in my method
public class Change{
public static void Change(double salesTotal, double customerPayment){
//Bill:a$130,b$55,c$25,d$5,e$1
//f75cents,g30cents,h1cents
double a,b,c,d,e,f,g,h;
a = b = c = d = e = f = g = h = 0;
…

Alex H
- 1
- 4