How do we call subclass methods in another class instead of its superclass?
•
Java
I want to call subclass functions in another class in Java. Do I do this?
The examples here are my superclasses and subclasses
public abstract class a { method 0; } class b extends a { method 1; }
There is another class call C. I want to do the following in class C is another class in the new file But in the same bag
class c { c val; public c { a var1 =( (b)val.method0()).method1; } }
But when I run the program, I get an exception declaring that the conversion type of cant is B. does anyone suggest getting rid of this?
This is the actual abnormal error I got (I wrote a demo in the code above)
Solution
Then, the way your code looks, and there is no restrictive modifier in your code (unless you do so), all you have to do is instantiate the subclass and call its method in your C class.
Are these static methods?
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码