Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Inheritance, abstract classes

Have Programming Question? Ask it here!
 
 
 


Andrew Meikle
Inheritance, abstract classes
0 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


Hi. I wish to thank you for answering my last question, but I had figured it out, but the GUI was very helpful. I could use someones help again with abstracts & a demo account. I know you will be thinking how could I write the code but not get the simplest part.I'm getting a little lost with child classes, but here goes and don't know what to call. First, the code works, I just can't finish the demo application.For class, I had to create a class named Account for a bank. Included an integer field for the account number and a double field for the account balance.Also included a constructor that requires an account number and sets the balance to 0.0. I included a set method for the balance. Also included two abstract get methods-one for each field. I created two child classes of Account: Checking and Savings. Within the Checking class, the get method displays the string"Checking Account Information", the account number and the balance. Within the Savings class, added a field to hold the interest rate, and require the Savings get method to display the string "Savings Account Information", the account number, the balance, and the interest rate. I have to write an application that displays both Checkin and Savings objects. Save as Account.java, Checking.java, Savings.java. In addition, I had to write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a loop to display data, save as AccountArray.java. My code is as follows:

public Account(int an)

{

accountNumber = an;

accountBalance = 0.0;

}

public void setBalance(double bal)

{

accountBalance = bal;

}

public abstract int getNumber();

public abstract double getBalance();

public abstract void getInfo();

}
public class Checking extends Account

{

public Checking(int a)

{

super(a);

}

public void getInfo()

{

System.out.println("Checking Account Information " +

getNumber() + " $" + getBalance());

}

public int getNumber()

{

return accountNumber;

}

public double getBalance()

{

return accountBalance;

}

}
public class Savings extends Account

{

double rate;

public Savings(int a, double r){

super(a);

rate = r;

}

public void getInfo()

{

System.out.println("Savings Account Information " +

getNumber() + " $" +getBalance() + " rate " + rate);

}

public int getNumber()

{

return accountNumber;

}

public double getBalance()

{

return accountBalance;

}

}

This is the DemoAccounts application I am having problems with. I can only get the Savings to print:

public class DemoAccounts

{

public static void main(String[] args)

{

Savings mySvAcct = new Savings(2345, 0.03);

 mySvAcct.getInfo();

}

}

This is the AccountArray:

public class AccountArray

{

public static void main(String[] args)

{

Account someAccts[] = new Account[10];

int i;

someAccts[0] = new Checking(101);

someAccts[1] = new Savings(201, 2.1);

someAccts[2] = new Checking(102);

someAccts[3] = new Savings(202, 2.2);

someAccts[4] = new Checking(103);

someAccts[5] = new Savings(203, 2.3);

someAccts[6] = new Checking(104);

someAccts[7] = new Savings(204, 2.4);

someAccts[8] = new Checking(105);

someAccts[9] = new Savings(205, 2.5);

for(i = 0; i <10; ++i)

someAccts[i].getInfo();

}

}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Inheritance, abstract classes
Inheritance, abstract classes  Hi. I wish to thank you for answering... a little lost with child classes, but here goes and don't know what to call... method for the balance. Also included two abstract get methods-one for each
What is Abstract classes in Java?
What is Abstract classes in Java?  What is Abstrack class in Java...,   Hi, In Java programming language we are used the Java Abstract class to declare some common characteristics of subclasses.This Abstract class
Advertisements
Abstract class,Abstract methods and classes
Abstract methods and classes     ... is used with methods and classesAbstract Method An abstract method one...(); Abstract Class In java programming language, abstract classes
Interfaces and Abstract Classes - Development process
Interface and Abstract Classes?  Hi Friend, Interface: Java does.... It relate classes from different types of hierarchy. Abstract Class: Any class... be embedded into these classes. Abstract class prevents from instantiating a class
Abstract Classes - Java Interview Questions
Abstract Classes  Why we cann't instantiate a Abstract Classes? Even if an Abstract Class does not have any abstract methods, but declaring the class as abstract prevents it from creating an instance. Why? Thanks in Advance
Java Inheritance and abstract - Java Interview Questions
Java Inheritance and abstract  1) Why we need to write the separate Interface in which we are not doing any operation except declaring empty abstract... the abstract methods. If the subclass need to use this methods then he can write
Abstract methods and classes
Abstract methods and classes     ... is used with methods and classesAbstract Method An abstract method one...(); Abstract Class In java programming language, abstract classes
inheritance
inheritance  how does one implement inheritance in java
inheritance
inheritance  hi.. pleaseeeeee i need a quick help(answer) in creating aprogrm in java by using inheritance for car in such away that .... Car is parent class and both of Private and Public Car extends it then both of Bus
Java Abstract Class Example
the behaviour of classes from the outside environment. Abstract class can be created... and some are unique to specific classes. An abstract class should...Java Abstract Class Example In this section we will read about the Abstract
Inheritance in Java
Inheritance, one of the important concepts of Object Oriented Programming.... Benefit of using inheritance: A code can be used again and again Inheritance in Java enhances the properties of the class, which means
abstract class
abstract methods. Abstract classes cannot be instantiated, but they can be extended...abstract class   Explain the concept of abstract class and it?s use with a sample program.   Java Abstract Class An abstract class
Inheritance,Inheritance in Java,Java Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
multiple inheritance - Java Beginners
)why java classes does not support Multiple Inheritance? JAVA CLASSES ONLY... Inheritance. Ans...>java classes doesn't support multiple inheritance,the practical...multiple inheritance  Why java does not support Multiple Inheritance
Abstract class and abstract method
Some key points about abstract methods are as following An abstract modifier identifies abstract classes and methods An abstract methods cannot be private because it defined in the other class. An abstract methods cannot
Interface Vs Abstract Class
) and non-public members abstract classes may or may not be a little bit... Interface Vs Abstract Class       There are three main differences between an interface and an abstract
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
Java: Inheritance
Java: Inheritance More on virtual by default Nested Classes, Part 2 Copyleft 2004 Fred Swartz MIT License
Abstract Factory Pattern
Abstract Factory Pattern       II Abstract Factory Pattern :  This pattern is one level of abstraction higher than factory pattern. This means that the abstract factory returns
Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
Multiple Inheritance
inheritance but by default Object class is super class for all the user defined classes and we can extend at most one class so each class can extend more than one class so java any how do multiple inheritance? Can you please explain
Java Abstract Class
. It may or may not have abstract methods. Abstract classes cannot be instantiated.... Which helps us to organize our classes based on common methods. An abstract class... is unique to specific classes. So you implement the superclass as an abstract
Abstract and Interface
abstract classes, java interfaces are slow as it requires extra indirection...Abstract and Interface  What is interface? When time is most suitable for using interface? Why we use interface instead of abstract? What
abstract class
abstract class  Can there be an abstract class with no abstract methods
abstract method
abstract method  Can we have abstract class with no abstract methods
abstract method
abstract method  is final method is in abstract class
Abstract class
Abstract class  what is an Abstract class
Abstract class
Abstract class  Can an abstract class be final
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi, java does not support multiple inheritance
PHP Inheritance Class
values in classes, we must use the inheritance when the structure...Inheritance in PHP: Inheritance is a property of Object Oriented Programming.... With the help of this property classes and objects  get more flexibility, scalability
Uses of abstract class & interface - Java Beginners
classes from different types of hierarchy. Abstract Class: Any class... into these classes. Abstract class prevents from instantiating a class...Uses of abstract class & interface  Dear sir, I'm new
Abstract and Interface
Abstract and Interface  what is the difference between Abstract and Interface accurateatly
abstract method
abstract method  Can a concrete class have an abstract method
Difference between abstract class and an interface
an abstract class is class which cannot extends multiple classes because java...Difference between abstract class and an interface The difference between abstract class and interface is one of the most popular question in the interview
abstract class - Java Beginners
use becomes necessary and useful ?give some examples of abstract classes..., In java programming language, abstract classes are those that works only... inherited from the abstract class (base class). Abstract classes
Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
Abstract class
Abstract class  j   An Abstract class is a base class which... with an abstract keyword. For more information, visit the following links: http://www.roseindia.net/help/java/a/java-abstract-class.shtml http://www.roseindia.net/java
abstract class
abstract class  abstract class AbstractClass{ } is possible and compile the class or any compile time error occur tell me the answer Blockquote
abstract class
abstract class  what is abstract class .why we use it or what is the need of this class?   Abstract class is like base class which contains abstract method and cannot instantiated.   Please go through
Inheritance in Spring
Inheritance in Spring       Inheritance Demo, In the example given below we are going to tell about the inheritance in the Spring framework. By inheritance we mean a way
Abstract class and interface in Java
variables) and non-public members abstract classes may or may not be a little bit...Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between
abstract wizard form controller
abstract wizard form controller  Hi In roseindia for abstract wizard form controller example contains half of the code. please send the remaing half of the code like controller classes
Abstract class
Abstract class  Calendar cal=Calendar.getInstance() We know that Calendar is an abstract class so it can't be instantiated. So how we can say that cal is an instance of Calendar??? Beginner Question I suppose. Thanks in advace
Concept of Inheritance in Java
Concept of Inheritance in Java Concept of Inheritance in Java is considered one of the important features of Object Oriented Programming. Inheritance as the name suggest is used to derive classes from other classes. The derived class
Java inheritance
Java inheritance   can the child access protected content of the parent if the child is in a different project   If you have considered different project as different package then the child cannot access the content
Interface and Abstract class
methods and these method implemented by sub classes. Abstract class definition...Interface and Abstract class  hello,, Can some body tell me what is the difference between an Interface and an Abstract class?   hi, Very
Multiple Inheritance
Multiple Inheritance  Why Java Doesn't have Multiple Inheritance It is Advantage or Disadvantage.........   Hi Friend, When we extends... and inconsistencies Java does not support Multiple Inheritance. Thanks
Abstract class - Java Beginners
are overrided in which that is implemented . thats all abt abstract classes...Abstract class  Why can use abstract class in java.?when abstract class use in java.plz Explain with program.   abstract class abs{ public
java inheritance
contain three classes, a SalesEmployee class, a SalesPerson class and a SalesAgent... would be good? public abstract class employees { protected double sales...; } public abstract void computetotalsales( ); } public class sales
Interface and Abstract class
be invoked if a main() exists. 8)In comparison with java abstract classes, java...Interface and Abstract class  Difference between Interface and Abstract class? Give some example   Difference Between Interface
 

 

 

DMCA.com