Home Answers Viewqa Java-Beginners Inheritance, abstract classes

 
 


Andrew Meikle
Inheritance, abstract classes
0 Answer(s)      2 years and 5 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();

}

}
View Answers









Related Pages:
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
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 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
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
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
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
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 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
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
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
Advanced Concepts with Classes - JDBC
Advanced Concepts with Classes  Advanced Concepts with Classes( Inheritance, Polymorphism, Overriding) i need help to create this application,than you Employees in a company are divided into the classes Employee, HourlyPaid
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
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
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
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
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
Java: Inheritance
Java: Inheritance More on virtual by default Nested Classes, Part 2 Copyleft 2004 Fred Swartz MIT License
( Inheritance,need help in Polymorphism, Overriding) - Java Beginners
( Inheritance,need help in Polymorphism, Overriding)  can any one please help me create this application,thank you Advanced Concepts with Classes( Inheritance, Polymorphism, Overriding) Employees in a company are divided
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
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
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
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
Classes in Java      ... other features like creation and implementation of the object, Inheritance etc...; by calling the different functions from the different classes through
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 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 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
Inheritance
Inheritance        OOPs.... Abstraction 4. Inheritance In OOPs, these concepts are implemented through a class... we will discuss Inheritance briefly:  -- Inheritance is the mechanism
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
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
( Inheritance, Polymorphism, Overriding)i need help - Java Beginners
( Inheritance, Polymorphism, Overriding)i need help  Advanced Concepts with Classes( Inheritance, Polymorphism, Overriding) i need help to create this application,than you Employees in a company are divided into the classes
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
Inheritance - Java Beginners
Inheritance  pls help me!!! Question: write an inheritance hierachy for classes Quadrilateral,Trapezoid,Parallelogram, Rectangle and Square. Use... of the Quadrilateral. Write a program that instantiates objects of the classes adn outputs each
Abstract Class in Java
. An abstract class cannot be instantiated. Abstract classes can be extended into sub classes. Abstract class can be declared as: abstract class...Abstract class in Java is a class that is declared using abstract keyword
inheritance
inheritance  how does one implement inheritance in java
Inheritance java Example
Inheritance java Example  How can we use inheritance in java program... of inheritance. Inheritance is a way of establishing a subtype from an existing object..., whose method eat() has been accessed by its sub classes Cat, Dog and Goat
An Abstract class may or may not have abstract method.
Description: An Abstract is also known as Abstract Base Class. Abstract Class... declaration is done in its derived class not in the abstract class. Abstract itself means incomplete so through inheritance it method method is defined. Program
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
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 - Java Beginners
of abstract class?   Hi friend, Abstract classes In java programming language, abstract classes are those that works only as the parent class... from the abstract class (base class). Abstract classes are not instantiated
abstract class and overriding - Java Beginners
friend, Abstract class : In java programming language, abstract classes...). Abstract classes are not instantiated directly. First extend the base class and then instantiate (create objects). Abstract classes are generic in nature
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
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
The abstract Keyword : Java Glossary
is available for other classes to extend by other classesAbstract keyword... provides a way to extend an actual class. We will not use new on abstract classes... on classes and methods.  In case of class declared with an abstract keyword
Multilevel inheritance - Java Beginners
Multilevel inheritance  Dear Sir, I'm posting you another question for which I need a more explanatory java coding(A lengthy one with more classes if possible) "Write a java program to create simple student object and inherit
c++ program of inheritance
. From this derive the classes curacct and savacct to make them more specific
Inheritance in java with example
Inheritance in java with example          Inheritance is one of the concept of the Object- Oriented programming. The advantage of using the inheritance

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.