• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

method in interface?

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Helper:
Can the methods in interface be synchronized?
Can private method be overriden?
Can transient variable be written to output files?
Thanks.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jordan,
Yes methods defined in interfaces can be synchronized. Since each class that implements the method will be required to handle it accordingly.
No, private methods can not be overridden because they are not visible by any other class (including subclasses).
Yes, transient variables can be written to output files. JLS only specifies that transient variables will not be serialized when the class is serialized.
Regards,
Manfred.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jordan,
I'm going to move this to Certification Study. This forum is only for reporting possible mock exam errors.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methods in interface cannot be synchronized.
see the following compile message:
<code>
Interface methods can't be native, static, synchronized, final, private, or protected.
</code>
Hope it helps.
Guoqiao

Originally posted by jordan gong:
Dear Helper:
Can the methods in interface be synchronized?
Can private method be overriden?
Can transient variable be written to output files?
Thanks.


 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jordan,
Can the methods in interface be synchronized?
No, this keyword is not allowed.
Can private method be overriden?
You can override a method that is visible to the subclass.Since the private methods are not, you cannot override them.
Can transient variable be written to output files?
Yes you can!However, you cannot expect this variable to be serialized.
Hope this helps,
Sandeep
 
jordan gong
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Helper:
I am totally confused. Some people state method in interface can be synchronized, some state cannot.
Which one is correct?
thanks.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jordan,
A method declared in an interface may not be declared synchronized; however, a method declared in a class which is declared within an interface can be synchronized.

If you remove the comments in front of the methodA line above and try to compile you will get an error.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
    Bookmark Topic Watch Topic
  • New Topic