Java Reference
In-Depth Information
Figure 6.6
The call to super() no longer works, since Television does not have a no-argument
constructor.
The BigScreenTV constructors must explicitly invoke one of the construc-
tors in the parent class. The following class shows a whole new BigScreenTV
class that uses the super() keyword and passes in arguments to a specific Tele-
vision constructor.
public class BigScreenTV extends Television
{
public String aspectRatio;
public short size;
public BigScreenTV(int channel)
{
this(“unknown”, (short) 40, channel);
System.out.println(“Inside BigScreenTV(int)”);
}
public BigScreenTV(String r, short s, int channel)
{
super(channel);
System.out.println(“Inside BigScreenTV(String, short, int)”);
aspectRatio = r;
size = s;
}
public BigScreenTV(String r, short s, int channel, int volume)
{
super(channel, volume);
System.out.println(“Inside BigScreenTV(String, short, int,
int)”);
aspectRatio = r;
size = s;
}
The following ParentDemo program invokes two BigScreenTV objects using
the new Television and BigScreenTV classes. Try to determine what the output
will be. Compare your answer with the actual output shown in Figure 6.7.
public class ParentDemo
{
public static void main(String [] args)
{
Search WWH ::




Custom Search