JME
JME

Reputation: 2353

Java public class with an internal method

I am attempting to convert a C# abstract class to a java class that has the same encapsulation and functionality. I understand you can make a class internal in Java by declaring the class without any modifiers, and this results in a private package. I would like to achieve something similar except where the class is public, some of the methods inside the class are public and some are internal.

The class I am modifying looks as follows,

//// This is C#
public abstract class Response
{
   public String Request{get; internal set;}

   public String Body{get; internal set;}

}

I would like to end up with something that ideally looks like this,

//// This is Java
public abstract class Response
{
    public abstract String getRequest(){}

    abstract String setRequest(String r){}

    public abstract String getBody(){}

    abstract String setBody(String b){}
} 

Can this be achieved?

Upvotes: 1

Views: 1684

Answers (1)

stinepike
stinepike

Reputation: 54682

There should be no body of abstract class

public abstract class Response
{
    public abstract String getRequest();

    abstract String setRequest(String r);

    public abstract String getBody();

    abstract String setBody(String b);
} 

Another thing. If you dont use any modifier then it won't be private. It will be package protected. that means that can be accessible from another class within the same package.

Upvotes: 1

Related Questions