-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractClass.java
33 lines (28 loc) · 977 Bytes
/
AbstractClass.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
abstract class Payment {
abstract void makePayment();
void paymentDetails() {
System.out.println("Payment details are being processed.");
}
}
class CreditCardPayment extends Payment {
@Override
void makePayment() {
System.out.println("Payment made using Credit Card.");
}
}
class PayPalPayment extends Payment {
@Override
void makePayment() {
System.out.println("Payment made using PayPal.");
}
}
public class AbstractClass {
public static void main(String[] args) {
Payment payment1 = new CreditCardPayment();
payment1.makePayment(); // Outputs: Payment made using Credit Card.
payment1.paymentDetails(); // Outputs: Payment details are being processed.
Payment payment2 = new PayPalPayment();
payment2.makePayment(); // Outputs: Payment made using PayPal.
payment2.paymentDetails(); // Outputs: Payment details are being processed.
}
}