hello frnds,
I have one more observation
In kathy sierra chapter 2 and section named "Returning a value" it was stated
"In a method with an object reference return type, you can return any
object type that can be implicitly cast to the declared return type".
That is fine.But my point is we can even return any object type that can be explicitly casted to declared return type subjected to the following condition.
class Parent{
public void testMe(){
}
}
class Child extends Parent{
public Child sample(){
Parent parent = new Child();
System.out.println("sample execute");
return (Child)parent;
}
}
public class testMe{
public static void main(
String[] args) {
Child child = new Child();
System.out.println("child method executed without exception"+child.sample());
}
}
Regards
Sri