nerdexam
Oracle

1Z0-804 · Question #9

Which two forms of abstraction can a programmer use in Java?

The correct answer is B. interfaces D. abstract classes. When To Use Interfaces An interface allows somebody to start from scratch to implement your interface or implement your interface insome other code whose original or primary purpose was quite different from your interface. To them, yourinterface is only incidental, something…

RAC Architecture

Question

Which two forms of abstraction can a programmer use in Java?

Options

  • Aenums
  • Binterfaces
  • Cprimitives
  • Dabstract classes
  • Econcrete classes
  • Fprimitive wrappers

How the community answered

(26 responses)
  • A
    8% (2)
  • B
    73% (19)
  • C
    15% (4)
  • F
    4% (1)

Explanation

When To Use Interfaces An interface allows somebody to start from scratch to implement your interface or implement your interface insome other code whose original or primary purpose was quite different from your interface. To them, yourinterface is only incidental, something that have to add on to thetheir code to be able to use your package. Thedisadvantage is every method in the interface must be public. You might not want to expose everything. *When To Use Abstract classes An abstract class, in contrast, provides more structure. It usually defines some default implementations andprovides some tools useful for a full implementation. The catch is, code using it must use your class as thebase. That may be highly inconvenient if the other programmers wanting to use your package have alreadydeveloped their own class hierarchy independently. In Java, a class can inherit from only one base class. *When to Use Both You can offer the best of both worlds, an interface and an abstract class. Implementors can ignore yourabstract class if they choose. The only drawback of doing that is calling methods via their interface name isslightly slower than calling them via their abstract class name.

Topics

#Java abstraction#interfaces#abstract classes#OOP

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice