java - Convert sub-type to super-type -
i have abstract super class a, , subclass b extends class.
public abstract class { } public class b extends { }
i have method returns type a, object b
public fetchtype() { a = new b(); return a; }
when call fetchtype method, want object a. in case, might have cast b a. can please advise how do that?
you cannot create object if type abstract.
here class a
abstract class, means never able create object a
.
this not allowed: a = new a();