public class Main { public static void main(String[] args) {
public class Customer {
private String id;
private String name;
public Customer(String id, String name) {
this.id = id;
this.name = name;
}
public String Id() { return name; }
public String Name() { return name; }
public void Name(String name) { this.name = name; }
}
}
} and i receive this error: C:\Users\byuka\IdeaProjects\LearningJava\src\Main.java:10 java: illegal character: ‘`’. so how can i correct it and what can focus on during encapsulation.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
You are running into two things here.
First, the error illegal character: '’ usually means there is a backtick () somewhere in the file. Java does not use backticks, so removing it should fix that error.
Second, you cannot declare the Customer class inside the main method. It needs to be defined outside of main. You also have a small bug where Id()returnsnameinstead ofid`.
Encapsulation itself means keeping fields private and accessing them only through public methods, so you control how data is read or changed. Focus on private fields, getters and setters, and avoiding direct access to class variables.
Heya, @byukusenge1122
Encapsulation means keeping data safe inside a class. In Java, this is done by making variables private and allowing access to them only through methods. This way, other parts of the program cannot change the data directly and accidentally break it.
Your error happens because the code contains invalid quote characters and because a class is declared inside the main() method, which Java does not allow. Java only accepts normal quotes " " and classes must be defined outside main().
The recommended solution is to move the Customer class outside main, make its variables private, and use getter and setter methods to read or update them.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.