• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Confused by enthuware.ocajp.i.v8.2.1479  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is as follows:

select 4 option(s)

Q : Which of these statements about interfaces are true?

1: Interfaces are always abstract.

2: An interface can have static methods.

3: All methods in an interface are abstract although you need not declare them to be so.

4: Fields of an interface may be declared as transient or volatile but not synchronized.
All fields of an interface are public, static, and final. Therefore, volatile, transient, and synchronized do not make sense for such fields.

5: Interfaces cannot be final.

6: In Java 8, interfaces allow multiple implementation inheritance through default methods.

The question marks answers 1,2,4,6 as correct. I feel option 1 is incorrect.

Since Java 8 now includes default and static methods and they are never abstract, you cannot assume the abstract modifier will be implicitly applied to all methods by the compiler.
(page 346 of Jeanne Boyarsky & Scott Selikoff's book, OCA: Oracle® Certified Associate Java SE 8 Programmer I Study Guide Exam 1Z0-808.)
to do some testing i wrote an interface which had a single default method and implementation. To which i then added the abstract keyword to the interface , which did not give any compile time errors. (Which shows that interfaces are abstract - yet at the same time the only method on the interface has an impl?)
 
Ranch Hand
Posts: 227
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I feel option 1 is incorrect.



To which i then added the abstract keyword to the interface, which did not give any compile time errors.  (Which shows that interfaces are abstract - yet at the same time the only method on the interface has an impl?)



It appears that you have answered your own question?
 
Charles O'Leary
Ranch Hand
Posts: 227
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... And welcome to the ranch Cozwaldo.  (I think you have this one figured out.)
 
Jim b jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:

I feel option 1 is incorrect.



To which i then added the abstract keyword to the interface, which did not give any compile time errors.  (Which shows that interfaces are abstract - yet at the same time the only method on the interface has an impl?)



It appears that you have answered your own question?



Thanks for the response , so just to clarify - Interfaces are always abstract , however an Interface may contain a static or default method (This method is not abstract - but as a whole the Interface is?) 
 
Charles O'Leary
Ranch Hand
Posts: 227
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cozwaldo cozwald wrote:Thanks for the response , so just to clarify - Interfaces are always abstract , however an Interface may contain a static or default method (This method is not abstract - but as a whole the Interface is?) 


Bingo! (same book)
Interface.png
[Thumbnail for Interface.png]
 
Jim b jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:

Cozwaldo cozwald wrote:Thanks for the response , so just to clarify - Interfaces are always abstract , however an Interface may contain a static or default method (This method is not abstract - but as a whole the Interface is?) 


Bingo! (same book)



Thanks again for your help, this was a very abstract problem for me to grasp.
 
Charles O'Leary
Ranch Hand
Posts: 227
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've enjoyed telling you that you were right all along!
 
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:. . . Bingo! (same book)

'Fraid not. The phrase “abstract datatype” does not mean the same as “abstract class”. A class is an abstract datatype, but can usually be instantiated directly. You have found the wrong section.
If you want the definitive answer, you need to go to the Java® Language Specification (=JLS). Fortunately you don't have to go far to find the answer. Last sentence in the first paragraph, and further on in §9.1.1.1. That also tells you about the keyword abstract.
 
Charles O'Leary
Ranch Hand
Posts: 227
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Charles O'Leary wrote:. . . Bingo! (same book)

'Fraid not. The phrase “abstract datatype” does not mean the same as “abstract class”. A class is an abstract datatype, but can usually be instantiated directly. You have found the wrong section.
If you want the definitive answer, you need to go to the Java® Language Specification (=JLS). Fortunately you don't have to go far to find the answer. Last sentence in the first paragraph, and further on in §9.1.1.1. That also tells you about the keyword abstract.


Campbell,
I did a "find" just to be sure.  But, please note that the word "class" was only used by you.  I think "abstract" was used in the correct context, especially as you outlined so eloquently in pointing out  §9.1.1.1.
 
Campbell Ritchie
Marshal
Posts: 60806
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The word was not used in the same context in ”abstract datatype”. Although the answer No 1 was correct, that quote didn't help to explain it.
 
Charles O'Leary
Ranch Hand
Posts: 227
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, 

possible answer provided per the question:

1: Interfaces are always abstract. 



Campbell Ritchie wrote: A class is an abstract datatype, but  ... The word was not used in the same context in ”abstract datatype”. Although the answer No 1 was correct, that quote didn't help to explain it.



My quote did not have any buts, exceptions, most of the times, and/or usuallys, so the word "always" was implied and was seemingly, I thought, exactly like your eloquent and concise §9.1.1.1.  The text (my quote) wriiten another way:  An interface is (always) an abstract datatype. (Period ... no buts) It defines a ...blah, blah, blah. 

So, not to beat a dead horse, but please help me to get my understanding correct on this.  I'd love to correct any misunderstanding that I may have regarding the quote that I provided.  

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!