Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error setX cannot be resolved or is not a field

$
0
0
Ok, so Eclipse allows me to fix this the issue in line 6 of TestGetSet by creating a field “setX” in type “GetSet”, but I know this is the wrong course of action. Can anyone please help me out?

public class TestGetSet {
	public static void main(String[] args) {
	
		GetSet obj1 = new GetSet();
			obj1.setX =(21);
			System.out.print(obj1.getX());
	}
}


public class GetSet {

	public int x = 22;
//	public int setX;

	public GetSet() {
		System.out.println("x = " + x);
		
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}	
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>