Professional Documents
Culture Documents
OK, A Strange & Common Question? If I mark a method as abstract, I mark the class also as abstract. But
if needed, Can I implement a few methods for which I know the implementation or is it that I have to mark
all methods as abstract in an abstract class.
Not at All. An Abstract class can very well have methods which are implemented and not abstract. Let's try
it out.
Create a driver class named Main which creates an instance of the above mentioned classes. The
function issuingAuthority() just displays the customer's credit card type.
Note: All text in bold corresponds to input and the rest corresponds to output.
//CreditCard
abstract class CreditCard{
private String cardNumber;
private String cardType;
private String holderName;
CreditCard(){}
CreditCard(String cardNumber, String cardType, String holderName){
this.cardNumber = cardNumber;
this.cardType = cardType;
this.holderName = holderName;
}
void setCardNumber(String cardNumber){
this.cardNumber = cardNumber;
}
void setCardType(String cardType){
this.cardType = cardType;
}
void setHolderName(String holderName){
this.holderName = holderName;
}
String getCardNumber(){
return this.cardNumber;
}
String getCardType(){
return this.cardType;
}
String getHolderName(){
return this.holderName;
}
void issuingAuthority(){
System.out.println("You have an Authority of : "+this.getCardType());
}
}
//Maestro
//MasterCard
//Visa
//Main
class Main {
}