Homework help please: Question in comments because it contains code.
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
@Loser66
I am so sorry. I don't know computer
its ok. I'll keep asking people
@iGreen
for number 2m my answer was I and II. For number 1, my answer was II and III. Can someone please check?
@TheSmartOne
@Teddyiswatshecallsme
@Teddyiswatshecallsme
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.
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.
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.
@dan815
@HaileyD
Join our real-time social learning platform and learn together with your friends!