Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (ellecullen):

Homework help please: Question in comments because it contains code.

OpenStudy (ellecullen):

public abstract class Account { public Account( ) { . . . } } public class BankAccount extends Account { private double balance; public BankAccount (double amount) { super( ); balance = amount; } } public class CheckingAccount extends BankAccount { private String customerName; public CheckingAccount (String name, double amount) { <Missing Statement> } . . . } Which of the following is an acceptable replacement for in CheckingAccount's constructor? I. balance = amount; customerName = name; II. super(amount); customerName = name; III. super (name,amount); (Points : 1) I only II only I and II II and III I, II and III Question 2. 2. Which of the following declarations are valid? I. Account acct = new BankAccount(10.00); II. CheckingAccount acct = new BankAccount (10.00); III. BankAccount acct = new CheckingAccount("Amy", 10.00); (Points : 1) I and II II and III I and III I, II, and III None of the three

OpenStudy (ellecullen):

@Loser66

OpenStudy (loser66):

I am so sorry. I don't know computer

OpenStudy (ellecullen):

its ok. I'll keep asking people

OpenStudy (ellecullen):

@iGreen

OpenStudy (ellecullen):

for number 2m my answer was I and II. For number 1, my answer was II and III. Can someone please check?

OpenStudy (ellecullen):

@TheSmartOne

OpenStudy (ellecullen):

@Teddyiswatshecallsme

OpenStudy (ellecullen):

@Teddyiswatshecallsme

OpenStudy (ellecullen):

another hard one : 3. Consider the following class: public class Fraction implements Comparable { private int num, denom; public int getNum () { return num;} public int getDenom () { return denom;} public double doubleValue () { return (double)num/denom;} } Which of the following would appropriately implement a CompareTo method, required by the Comparable interface? I. public int CompareTo(Fraction other) { return getNum() * other.getDenom() - getDenom() * other.getNum(); } II. public int CompareTo(Object other) { double x = doubleValue(); double y = ((Fraction)other).doubleValue(); if (x < y) return -1; else if (x > y) return 1; else return o; } III. public int CompareTo(Object other) { return (int) (doubleValue() - ((Fraction)other).doubleValue()); } (Points : 1) I only II only I and II II and III I, II, and III I think the first the I on this could be one of the answers.

OpenStudy (espex):

To answer your 1st question, you need to look at what your local variable is as well as what was defined in your parent class.

OpenStudy (espex):

For your 2nd question, look at the objects that are being created and ask yourself which one could be cast into the definition. For example, if you have a class Shape, and a class Circle that extends shape, you know that ALL circles can be a shape, but not all shapes are circles.

OpenStudy (ellecullen):

@dan815

OpenStudy (ellecullen):

@HaileyD

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!