开发者

What is a public interface?

"Using only the public interface of the linked list class, write a method public static void reverse(LinkedList staff) that reverses the entries in a linked list."

The part of all of that I'm not understanding is t开发者_JAVA技巧he first part. What does it mean by public interface of linked list class? Do I create a new class file that starts with something like public interface linkedlist? Can I add the method as a inner class within my main class?


The question is unnecessarily vague. What it's trying to ask is "using only the methods and fields of LinkedList that have the access modifier public, write this method."

You can put the method you write in any class you like, but the restriction says that you may only use public methods and fields on LinkedList to write it.

This also means that you can't create a subclass of LinkedList and use its protected methods.


The public interface of a class are its public properties (variables or fields you can read the values of or assign to) and methods (functions you can call).

So, the assignment is to create something that is not a subclass of LinkedList. Creating a subclass would give you access to protected methods for example. You need to create something external to LinkedList, for example:

void MyMethod()
{
    LinkedList l = new LinkedList();

    // do something with l here.
}


"Public interface of linked list class" means only public methods of the LinkedList class. See the javadoc, there is a list of all public methods, or create new LinkedList instance and let your IDE suggest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜