Guys can you please explain to me how come the output of this example is:
Exam1
This is Tennis Shoes
derived class
This is a white Tennis Shoes is created
If you could explain to me what exactly happened after we created an Object of White Tennis Shoes and what happened.
Please guys don't tell me do your homework or something I'm just preparing for my exam and I this is an old question.
The code is below:
class Shoes{
public Shoes(){
this("you have created a shoes Object");
System.out.println("This is the base class");
}
public Shoes(String s){
System.out.println(s);
}
}
class TennisShoes extends Shoes{
public TennisShoes(){
this("This is Tennis Shoes");
System.out.println("derived class");
}
public TennisShoes(String s){
super("Exam1");
System.out.println(s);
}
}
class WhiteTennisShoes extends TennisShoes{
public WhiteTennisShoes(String s){
System.out.println(s);
}
}
class ConstructorPrintingTester{
public static void main(String[] args){
WhiteTennisShoes shoesObj;
shoesObj = new WhiteTennisShoes("This is a white Tennis Shoes is created");
}
}
this("xxxx")it will call another constructor inside the current constructor that's why it stopped me after thinking 15mins! thanks to phihag it's really clear now and I like the way he listed them down which is very helpful.super()constructor Java will create one for me. so this is why I really couldn't understand a thing from the output.