Hi everyone I have a final exam for my Java class tomorrow and wondering if anyone could tell me if my answers are right? The questions are True/False. Thank you all!

  1. True/False — An interface may only contain method headers.
  2. True/False — An interface may not contain instance variables.
  3. True/False — Interfaces may be extended.
  4. True/False — When a class implements an interface, it must implement all of the methods in that interface.
  5. True/False — A class can implement only one interface.
  6. True/False — A class can extend another class, or implement an interface, but not both.
  7. True/False — The Comparable interface is often implemented by classes that require sorting.
  8. True/False — Interfaces are Java's way of simulating multiple inheritance (having more than one base class).
  9. True/False — The compiler enforces interface semantics.

  10. False, it can contain initialized public/static variables

  11. True, interfaces cannot be instantiated so makes sense to have no instance vars
  12. False if it means "class extend someInterface"? True is "someInterface extends otherInterface"?
  13. False? if it doesnt implement all methods it must be called abstract?
  14. False
  15. False
  16. True
  17. True? My professor says yes but people online seem to have mixed opinions about this though.
  18. False? semantics is always up to the programmer?

Recommended Answers

All 4 Replies

4 Is true for the exact reason you typed

For #3, I think it is about meaning of words. I feel that implements is actually just a syntax for Interface and extends is for abstract. However, the language attempts to involve its meaning to the program language. I am not from a native English speaking country, so both words aren't that different in programming language.

For #8, to me, it is ture in general. It could be false if you are going to argue about the meaning of the word inheritance. Anyway, I would give it a true.

No 3..

    interface A {void x();}
    interface B extends A {void y();}

just try it.

No 4. Depends on whether the class is defined as abstract or not (question is not clear)

No 8. Java Language Spec says "This (multiple) interface inheritance allows objects to support (multiple) common behaviors without sharing any implementation."

No 4 also depends whether or not there is a super class which contains an implementation for a method with that name.
No 17. True, if (and only if) we are talking about SIMULATING multiple inheritance, since you're not actually inherriting anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.