I have classes SearchToUser and getFilesToWord. GetFilesToWord must inherit SearchToUser fields. Extending works if an empty construction in SearchToUser-class, otherwise:
cannot find symbol
symbol : constructor SearchToUser()
location: class SearchToUser
public class GetFilesToWord extends SearchToUser{
^
1 error
make: *** [all] Error 1
I cannot understand why the empty constructor is required for extending.
[Added]
-- ALERT ERRR! USE COMPOSITION! Left as an "bad" example -- Composition VS Inheritance
It works but can you spot some weaknesses? Could I make the searchTerm private, create public method for it, create object of SearchToUser for the parameter in GetFilesToWord?
SearchToUser.java
public class SearchToUser {
public static GetFilesToWord geader;
public static String searchTerm;
SearchToUser(String s){
searchTerm=s.trim().toLowerCase();
files=geader.getFilesToWord(s);
}
...
}
GetFilesToWord.java
public class GetFilesToWord extends SearhToUser{
public GetFilesToWord(){super(SearchToUser.searchTerm){
...
}