Hi there, Can someone help me why the following code does not compile. Why not? public class WIDGET { private String x

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

Hi there, Can someone help me why the following code does not compile. Why not? public class WIDGET { private String x

Post by correctanswer »

Hi there,
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.
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply