public class Star extends Object {
Star(){
System.out.println("Star");
}
Star(String s1){
super();
System.out.println(s1+"is a Star");}
Star(String s2, String s3){
this("Mervury");
System.out.println(s2+"and"+s3+" are also Stars");}
public static void main(String[] args){
Sun sun=new Sun();
Sun sun1=new Sun("Venus");
Sun sun2= new Sun("Mars", "Eaarth");
}
}
class Sun extends Star{
public Sun(){System.out.println("Star Wars1");
}
public Sun(String v1){ super(v1,"Saturn");
System.out.println("Star Wars2");}
public Sun (String v2, String v3){
if (v2.substring(0,v2.length()).length()>v3.length())
System.out.println("Mission to Mars");
else
System.out.println("Earth");
}
}
For the above code, the answer of compiling the code will be:
1. Star
2.Star Wars1
3.Mercury is a star
4.Venus and Saturn are also star
5.Star Wars2
6.Star
7. Earth
My question is, when compile the third constructor in subclass Sun, Sun sun2= new Sun("Mars", "Earth"); why the line 6 Star get print out?
Thanks for attention