Java Challenge

I’ve encontered the following block of code while studying for Java Certification:

class Clothes {
    Clothes (String s) {  }


class TShirt extends Clothes {  }

However, this code have a mistake. Anyone could tell what is it??
Next post I’ll tell the answer… think about it.


2 thoughts on “Java Challenge

  1. Hey Sr.

    Would The right code be this? :

    class Clothes {
    private String s;
    Clothes (String s) {
    this.s = s;


    class TShirt extends Clothes {
    TShirt(String s){

  2. The reason of the mistake, is that the superclass does not defines a default constructor (without parameters), thus, all subclasses are forced to define a constructor, making a call to the superclass constructor, supplying the desired parameters.

    The TShirt class is one possibility. Another is:

    class JavaTShirt extends Clothes {
    JavaTShirt() {

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s