Question: Can someone help me why the following code does not compile. Why not? public class WIDGET { private String x = '';

Can someone help me why the following code does not compile. Why not? 

 

public class WIDGET 

 {    private String x = '';    

private static final int Y = 10;    

public String getX()    {    

 return x;   }    

public void setY(int aNumber)    

{     Y = aNumber;   }    

public void SETX(String aString)    

{     x = aString;   }   

 public void addToX(String x)   

{     x = this.x + x;   }

}

 

 

Possible answers below:

 

The method addToX does not set the instance variable x to a new value.

 

The method getX should have a parameter.

 

The declaration of the field Y is not valid.

 

In setY It is illegal to assign a value to field Y.

 

The method SETX does not follow naming conventions.

 

There is a brace (curly bracket) too many.

 

There is no constructor.

 

In the addToX method the + operator is being applied to strings. 

 

The class name is not valid.

 

The field x is not correctly initialised.



Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The reason the code does not compile is due to the following issue In se... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!