• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriden run() Method of Runnable Interface

 
sr shashidhar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi frndz,

Why we won't get any Exception/Error when we are creating user-defined thread with

"synchronized public void run()" implementing runnable interface

where we suppose to override

"public void run()" of Runnable interface in user-defined thread...?



Thanks in advance
 
Paul Clapham
Sheriff
Posts: 21155
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because there's nothing wrong with using "synchronized" in that position.

Perhaps you could explain what exception you expected would be thrown, and why?
 
sr shashidhar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply sir...

Actually the Method signature in Runnable interface is "public void run()",

according to "overridden and Interface" concept, we have to override methods of interface in subclass(child class)
with same Method signature right sir...?

My doubt is that, in Super Class(i.e., in Runnable class) we don't have "synchronized keyword" in method signature

"public void run()"

how can we override run method of super class in subclass using "synchronized keyword" which was not in super class method signature

"synchronized public void run()"

...?
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The synchronized keyword is simply not belonging to the method signature.
I suggest you read the Java Language Specification for that matter.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method signature is differrent than the declaration of the method. The method is declared as synchronized. That doesn't mean that synchronized is part of the signature
 
sr shashidhar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Manuel Petermann and Jayesh A Lalwani...
 
James X Peterson
Whizlabs Java Support
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,


nice question .Manuel Petermann its really helpful link.


Regards,
James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic