aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Basic concept problem?" Watch "Basic concept problem?" New topic
Author

Basic concept problem?

Sashi Gundoji
Greenhorn

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

Regards,
Sashi
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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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: http://aspose.com/file-tools
 
subject: Basic concept problem?