• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 5 Review Question 1 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Saumyaraj Zala
Ranch Hand
Posts: 75
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Question is like what modifiers are implicitly applied to all interface methods in which option saying abstract is marked incorrect.
If a interface is like:

wont abstract be implicitly applied to the method?
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saumyaraj Zala wrote:wont abstract be implicitly applied to the method?
No not to all, as It is mentioned in that answer, It was assumed to be abstract before Java 8 because since Java 8 we can have default and static methods which has their defined body in interface  and you know abstract methods can't have body so you can't say ALL interface methods implicitly have abstract modifiers as there can be default and static methods too.
 
Sushma Gurram
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Patekar wrote:
Saumyaraj Zala wrote:wont abstract be implicitly applied to the method?
No not to all, as It is mentioned in that answer, It was assumed to be abstract before Java 8 because since Java 8 we can have default and static methods which has their defined body in interface  and you know abstract methods can't have body so you can't say ALL interface methods implicitly have abstract modifiers as there can be default and static methods too.



Thank you. I was about to ask the same question.
 
Saumyaraj Zala
Ranch Hand
Posts: 75
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Patekar wrote:
Saumyaraj Zala wrote:wont abstract be implicitly applied to the method?
No not to all, as It is mentioned in that answer, It was assumed to be abstract before Java 8 because since Java 8 we can have default and static methods which has their defined body in interface  and you know abstract methods can't have body so you can't say ALL interface methods implicitly have abstract modifiers as there can be default and static methods too.


Agreed! But there are some examples later in the excerices that dont have the abstract modifier in it and still the code compiles!
eg; public void hello();

wont this compile?
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saumyaraj Zala wrote:Agreed! But there are some examples later in the excerices that dont have the abstract modifier in it and still the code compiles!
eg; public void hello();

wont this compile?
Yes It will compile. Since this is not a default Or a static method of an interface so implicitly absract modifier is applied for this method.

Even you don't need to write public modifier as implicitly It is applied to all methods of interface, let that be default Or static Or abstract method of an interface, that is why option B is correct.
 
Saumyaraj Zala
Ranch Hand
Posts: 75
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Patekar wrote:
Saumyaraj Zala wrote:Agreed! But there are some examples later in the excerices that dont have the abstract modifier in it and still the code compiles!
eg; public void hello();

wont this compile?
Yes It will compile. Since this is not a default Or a static method of an interface so implicitly absract modifier is applied for this method.

Even you don't need to write public modifier as implicitly It is applied to all methods of interface, let that be default Or static Or abstract method of an interface, that is why option B is correct.


So wont the answer include that abstract modifier will be implicitly applied or is it like it has not been included in answer because the abstract modifier does not always get included?
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes abstract modifier is not correct answer because since Java 8 abstract is not always applied to all methods of an interface because some of them can be deafult Or static methods. See below code
  • Implicitly public modifier will be applied to all three methods so option B is correct.
  • abstract modifier is applied only to methodOne() because that method is not default Or static which has body as methodTwo and methodThree so option E is incorrect.
  •  
    Saumyaraj Zala
    Ranch Hand
    Posts: 75
    AngularJS Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, I understood the point that abstract modifier cant be appied ALWAYS as there can be default or static methods present but it gets applied sometime and that was why I was confused. I think it would be more clearer If question stated which would be ALWAYS applied.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic