Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

The reason the code does not compile is due to the following issue In se... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCP Oracle Certified Professional Java SE 11 Developer Practice Tests Exam 1Z0 819 And Upgrade Exam 1Z0 817

Authors: Scott Selikoff, Jeanne Boyarsky

1st Edition

1119696135, 978-1119696131

More Books

Students also viewed these Programming questions