Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First thing, <code>super</code> doesn't work the way you have used it. when you extend a class, <code>CarRental</code> in your case, you inherite all <code>public</code> and <code>protected</code> members of that class. so to use a variable of your super class, you dont have to prefix <code>super</code>, you can just use the variable as if the child class holds it. so instead of </p> <pre><code>super.dailyRentalFee = 79.99; </code></pre> <p>use</p> <pre><code>dailyRentalFee = 79.99; // since dailyRentalFee is protected in class CarRental // this will work </code></pre> <p>similarly,</p> <pre><code>super.totalRentalFee = super.dailyRentalFee * super.getRentalDays() + this.dailyChauffeurFee * super.getRentalDays(); </code></pre> <p>should be written as </p> <pre><code>totalRentalFee = dailyRentalFee * getRentalDays() + this.dailyChauffeurFee * getRentalDays(); </code></pre> <p>provided, the method <code>getRentalDays</code> is public in the <code>CarRental</code> class.</p> <p>and about the error you mentioned in @Jeroen's answers' comments, make sure <code>LuxuryCarRental</code> and <code>CarRental</code> are in the same <code>package</code>. To be simple, make sure both files are in the same folder.</p> <p><strong>EDIT:</strong></p> <p>Your code doesn't contain a <code>main</code> method, that is why that error is produced. You should have a <code>main</code> method in your program for it to execute. That is the starting point of all java applications. so define a class with a <code>main</code> method inside and then create a <code>LuxuryCarRental</code> object and perform your computations there. for example,</p> <pre><code>class Sample { public static void main(String[] args) { //this is how all main methods would look LuxuryCarRental luxuryCar = new LuxuryCarRental("A",62020,"SUV",10,true); //call the LuxuryCarRental methods as per your coding requirements } } </code></pre> <p>see, its simpe,</p> <pre><code>class CarRental { //CarRental code } class LuxuryCarRental { //LuxuryCarRental code } class Test { public static void main(String[] args) { LuxuryCarRental luxuryCar = new LuxuryCarRental("A",62020,"SUV",10,true); luxuryCar.display(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload