Reputation: 69
i have a abstractclass "HotelReviewClass" & "RestaurantReviewClass" where i want to initializate the variables which are not commun and commun go to "super" class
BUT i have a error "constructor call must be the first statement in a constructor" How i can initilizate that uncommun variables ( because "HotelReviewClass" & "RestaurantReviewClass" variables are not equal)
package pt;
public class HotelReviewClass extends AbstractReview{
private String ratingService;
private String ratingLocal;
public HotelReviewClass(String grade, String comment, String service, String local, String owner){
this.ratingService = service;
this.ratingLocal = local;
super(grade, comment, owner);
}
}
Upvotes: 1
Views: 53
Reputation: 424993
The first line of any constructor that calls a super constructor must be the call to the super constructor.
Just move the call up to the first line:
public HotelReviewClass(String grade, String comment, String service, String local, String owner){
super(grade, comment, owner);
this.ratingService = service;
this.ratingLocal = local;
}
Upvotes: 3