Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Introducing IntelliJ and Unpacking Packages Introducing IntelliJ and Unpacking Packages Creating Classes and Perusing Packages

How can I convert a private string into a public string?

package com.teamtreehouse;

import com.teamtreehouse.data.Person;

public class Main {

public static void main(String[] args) {
    Person person = new Person( name: "Allen");
}

}

The word Person is set to private, and I need to convert it to public, how do I perform that task using IntelliJ? When you look at the screen the word Person appear to be public but if I look at the Person.java folder it set as private.

Thanks, Allen

1 Answer

Steven Parker
Steven Parker
231,184 Points

It's not access level but that any method variable has a scope limited to that method. To create a persistent public attribute, you'd probably need to declare it outside of the method, perhaps like this:

public class Main {
    public Person person;
    public static void main(String[] args) {
        person = new Person(name: "Allen");
    }
}