Change the method to return the actual data type instead of java.lang.Object.
If the method returns objects of types that do not share a common interface or a class, create the new interface or class and encapsulate the object in it.
public ObjectDowncast_Solution( String str ) {
super();
this .str = str;
}
public String getString(){
return str;
}
private String str;
public static void main(String[] args){
ObjectDowncast_Solution example = new ObjectDowncast_Solution("Hello World!");
String str = example.getString();
System.out.println( str );
}
|
|