Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Price
- {
- private double price;
- public Price(double p){price = p;}
- public double getPrice(){return price;}
- public String toString(){return "Price is " + getPrice();}
- }
- class DiscountPrice extends Price
- {
- public DiscountPrice(double p){super(p);}
- public double getPrice(){return super.getPrice()*.85;}
- /* copied from the Price class
- private double price;
- public Ticket(double p){price = p;}
- public double getPrice(){return price;}
- public String toString(){return "Price is " + getPrice();}
- */
- }
- public class Inheritance_ex2
- {
- public static void main(String[] args)
- {
- Price t = new Price(2500);
- System.out.println(t);
- System.out.println("\n");
- Price t2 = new DiscountPrice(2500);
- System.out.println(t2);
- System.out.println("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement