Report this

What is the reason for this report?

what is Encapsulation?

Posted on February 2, 2026

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.