Results 1 to 4 of 4
- 02-16-2009, 10:34 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 4
- Rep Power
- 0
Ask for help on Java access to protected methods
Hi,
I use a java toolkit, and I want to access a class (Morphy) in it.
There is only one constructor function for class Morphy:
Morphy(WordNet wn).
As some methods in this class are protected, and I will call them.
Here is my code:
import danbikel.wordnet.WordNet;
import danbikel.wordnet.Morphy;
public class wn extends Morphy {
public void test(){
wn a=new wn();
a.morphWord("running","v"); // it is a protected method in Morphy
}
}
It just report an compile error: cannot find symbol: symbol : constructor Morphy().
Can anyone tell me how to fix the problem? I don't know how to add the constructor in my code.
Thanks a lot in advance.
-
Whenever you extend a class, your new class's constructor will always first call the parent class's constructor. This can be an explicit call by having a call to super(...) as the first call in the wn constructor, or if not explicitly done, then the compiler will make an implicit call to the default Morphy constructor which has no parameters. Since this constructor doesn't exist, the compiler is throwing the exception. The fix is to have an explicit call to the Morphy constructor with the proper Wordnet parameter as the first line of your wn constructor. i.e.,
Make sense?Java Code:public wn(WordNet wordnet) { // explicit call to the parent class's constructor with proper parameter super(wordnet); //... the rest of your wn constructor goes here }
also, please capitalize the first letter of all classes if you want to follow Java coding conventions.Last edited by Fubarable; 02-16-2009 at 11:47 PM.
- 02-17-2009, 12:05 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 4
- Rep Power
- 0
thank you very much, Fubarable.
It is done following your guidance.
-
Similar Threads
-
[SOLVED] Unable to access array defiened in constructor in other methods.
By Shyam Singh in forum New To JavaReplies: 1Last Post: 07-20-2008, 04:42 PM -
The different of static void,protected,and void in methods?
By Winarto in forum New To JavaReplies: 5Last Post: 01-24-2008, 11:53 PM -
Error: Cannot access protected member long getTimeInMillis() in class Calendar
By cachi in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:53 AM -
help with protected method in vector class
By katie in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 10:59 PM -
confused with protected qualifier.....plz solve this query...
By money123 in forum New To JavaReplies: 3Last Post: 07-30-2007, 07:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks