hi, i just have many questions regarding abstract class, please briefly explain if you may. thanks.
1. what is the difference between declaring public abstract class and abstract class ?
2. should abstract class have a constructor? i know by default it has one, but since abstract class doesn't have an object and its constructor cannot be instantiated, then why we need a constructor?
3. does abstract class normally have public methods?
4.does abstract class have concrete functions as well? and why would we have full function in an abstract class?
lastly, what is wrong with my Customer constructor() in the customer class?
abstract class CD
{
double interest_rate;
int months;
public CD(double interest_rate, int months)
{
this.interest_rate= interest_rate;
this.months= months;
}
abstract double calc_interest();// this method is not finished !!!
public String toString()
{
return ("Interest Rate: "+ interest_rate + "\n" +
"Months: "+ months +"\n");
}
}
class Customer extends CD
{
String name;
String address;
double deposit;
// default constructor
public Customer()
{
name = "no name";
address = "no address";
deposit = 0;
}
// constructor
public Customer(String name, String address, double deposit)
{
this.name = name;
this.address = address;
this.deposit = deposit;
}
public String toString()
{
return ("Name: " + this.name + "\n" +
"Address: " + this.address + "\n" +
"Deposit "+ this.deposit + "\n");
}
public double calc_interest()
{
double interest = (deposit * interest_rate * months/12.0);
return interest;
}
}
class Inherit13
{
public static void main(String args[])
{
double total_interest;
Customer person = new Customer("henry li", "xxx street, city, MA, xxxx", 10000.00);
CD person_ref;
person_ref = person;
person_ref.interest_rate = 0.05;
person_ref.months=12;
person_ref.toString();
// let us now display the data
/*
System.out.println(" customer's name " + person.name);
System.out.println(" customer's address" + person.address);
System.out.println(" customer's initial deposit" + person.deposit);
// we can now display the following data
System.out.println(" the rate of interest on the CD is " + person_ref.interest_rate + "percent");
System.out.println(" the number of months the principal is deposited for is " + person_ref.months);
// we can now display the total interest earned
total_interest = person_ref.calc_interest();
System.out.println(" the total interest on the deposited amount is " + total_interest);
*/
}
}
sorry, many questions. anyone help i really appreciate.