From leavens@cs.uiowa.edu Mon May 7 19:27:27 2001 MIME-Version: 1.0 Date: Mon, 07 May 2001 19:28:17 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Elise Anderson Subject: Re: Questions Content-Type: text/plain; charset=us-ascii Elise you wrote: > What is the difference in an Interface and a class? > (Just so I am totally clear) A Java interface just gives the protocol of an object, so it's a collection of instance method signatures. All the methods in an interface are public and abstract, implicitly. Being abstract means that they can't have any implementation. In a class, you can also have non-public methods, and methods can also be static (as opposed to instance methods) and you can write constructors and instance fields as well. JML allows you to write model instance fields in interfaces, but in normal Java you can't have instance fields in intefaces (you can only have public static final fields). Interfaces can extend multiple other interfaces, but a class can only extend one other class (it's superclass, so Java is a single inheritance language). A class can, however implement several interfaces. One way to think of Java interfaces is as weak specifications. When a class implements an interface, it must implement all the methods specified in it, with the given signatures. In JML, an interface specification can also include behavior, which the implementing class must satisfy. I'm sure there are other minor differences, but these are the main ones, I think. > And what is the difference between unchecked and > checked exception (excluding residing on RunTime... or > Exceptions type)? See Liskov's chapter 4, section 2 for a good explanation. In brief, the Java compiler makes sure that client code handles any checked exceptions that a method may throw, and checked exceptions have to be explicitly declared when thrown. Neither of those is true for unchecked exceptions. Gary