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.

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 ?

Well, what's the difference between declaring public class and 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?

For subclass constructors to use, maybe, you think?

3. does abstract class normally have public methods?

An abstract class can and does have, just about, anything you want it to have.

4.does abstract class have concrete functions as well? and why would we have full function in an abstract class?

If most, if not all, subclasses would do the some of the same actions, then what is the point of each subclass having to define that action?


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.

A subclasses constructor will always call a super constructor, if you don't add a call to a super constructor manually, then the compiler adds a call to the super classes default constructor. But, when you define a constructor for a class, that class no longer has a default constructor, so what super constructor is your Customer class calling?

And next time, do your homework yourself.

well, first of all thanks for all the inputs. it is the code given by my professor and for us to modify and add things he wants us to add. so please do not assume too early people here are just lazy bums. i would say lazy student wouldn't even bother posting questions.

i would say lazy student wouldn't even bother posting questions.

Do not be so judgmental, If you hang around here long enough you will see your fair share of them.

well, first of all thanks for all the inputs. it is the code given by my professor and for us to modify and add things he wants us to add. so please do not assume too early people here are just lazy bums. i would say lazy student wouldn't even bother posting questions.

Well, I would say a non-lazy student would post the questions and his answers to them and ask for corrections and/or confirmation. Simply posting a homework assignment is lazy. It shows that the only effort you are willing to give to your assignment is to ask for somebody to do it for you, i.e. no real effort at all.

Comments
eggjactly

Well, I would say a non-lazy student would post the questions and his answers to them and ask for corrections and/or confirmation. Simply posting a homework assignment is lazy. It shows that the only effort you are willing to give to your assignment is to ask for somebody to do it for you, i.e. no real effort at all.

i really don't feel like arguing this kind of thing in here... but i really don't understand first of all i wasn't asking anyone to do my homework but one error that I couldn't figure it out because i am new to the abstract class. secondly if i just wanna get my hw done then why would i post the 4 questions at the beginning sounds like i try to understand something. anyway, i think you should never help someone who you think not worth helping anyway. so don't bother posting with attitude... i don't assume anyone needs that.

Well, I would say a non-lazy student would post the questions and his answers to them and ask for corrections and/or confirmation. Simply posting a homework assignment is lazy. It shows that the only effort you are willing to give to your assignment is to ask for somebody to do it for you, i.e. no real effort at all.

and i am just curious, the code i posted was already done (with one compile error which i needed correction). so where did masijade come up with that "simply posting a homework assignment" thought?

Because it looks like code that was provided to you with an error that you were to fix. Everyone of those questions that you posted look exactly like a homework question, so much so, that I can guarantee they are.

P.S. I did not insult you, I simply stated my beliefs. If you take offense at someone speaking there mind, maybe you should look into why that is.

This question has already been answered. Start a new discussion instead.