File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Basic concept problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Basic concept problem?" Watch "Basic concept problem?" New topic

Basic concept problem?

Sashi Gundoji

Joined: Jan 30, 2007
Posts: 10
Hallo all,

I need one basic information about below program. I would like to know is this really works.

-> Base class
public abstract class test {

public Synchronized abstract void readData();


-> Child class1

public class test1 extends test {

public Synchronized abstract void readData() {
read state1;
read state2;

-> Child class2

public class test2 extends test {

public Synchronized abstract void readData() {
read state3;
read state4;

If this way possible, then i would like to know is that readData method will be Synchronized. If one Daemon is calling child1 readData Method and another daemon is calling child2 readData simultaneously, then what will happen.

thanking you

Sidd Kulk
Ranch Hand

Joined: Feb 20, 2007
Posts: 152
This code wont even compile. A method cannot be defined as 'abstract' and 'synchronized' at the same time, because abstract means that the method doesn't posses a body, while synchronizing is related to method implementation.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Yes, there are all sorts of reasons why the above won't compile, but I think what he's really after is something about the different child classes which each have a method, synchronized or not, that override a common synchronized method (it wouldn't need to be abstract.)

The short answer is that inheritance has nothing to do with it. Each individual object has its own "lock" for synchronization. Two threads will be able to call readData() on any two distinct objects simultaneously with no interference, whether those two objects belong to the same class or to two different classes.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Basic concept problem?
It's not a secret anymore!