Question
1. Refer to the Java classes below: public class BankAccount { private double myBalance; public BankAccount() { myBalance = 0; } public BankAccount(double Balance) {
1. Refer to the Java classes below: public class BankAccount { private double myBalance; public BankAccount() { myBalance = 0; } public BankAccount(double Balance) { myBalance = balance; } public void deposit (double amount) { myBalance += amount; } public double getBalance() { return myBalance; } } public class SavingsAccount extends BankAccount { private double myInterestRate; public SavingsAccount() { /* implementation not shown */ } public SavingsAccount(double balance, double rate) { /* implementation not shown */ } public void addInterest() { /* implementation not shown */ } } Which of the following correctly implements the default constructor of the SavingsAccount class?
I myInterestRate =0; super(); II super(); myInterestRate = 0; III super();
Select one:
a. II only
b. I and II only
c. II and III only
d. III only
e. I, II, and III
2. In the following Haskell function identify the code that implements the base case.
sfac s n = if n == 0 then s else sfac (s*n) (n-1)
Select one:
a. if n == 0
b. if n == 0 then s
c. else sfac (s*n) (n-1)
d. There is no base case in this example
3. True/False: An advantage of the array is that is ensures that all values are always in sorted order.
4. In the following example EBNF grammar, what does the symbol
Select one:
a. An Integer
b. A real number
c. A character
d. A string
5. Using your knowledge of binding, lifetime, and scope rules, determine what the following code will produce as output ... assume that the code in in the Java language:
public class test { public static void main(String[] args) { int x,y; x=1; y=my_int(x); System.out.println(x); } static int my_int(x) { x = 5; return(x+x); } }
Select one:
a. 5
b. 10
c. 1
d. None of these answers
6. Given that n and count are both of type int, which statement is true about the following Java code segments? I for (count=1; count <= n; count++) System.out.println(count); II count = 1; while (count <= n) { System.out.println(count); count++; }
Select one:
a. I and II are exactly equivalent for all input values of n.
b. I and II are exactly equivalent for all input values n>= 1, but differ when n<= 0.
c. I and II are exactly equivalent only when n = 0.
d. I and II are exactly equivalent only when n is even.
e. I and II are not equivalent for any input values of n.
7. Which of the following choices is the following regular expression most likely to match?
[-+]?[0-9]*\.?[0-9]+
Select one:
a. A floating point number
b. An integer number
c. A telephone number
d. A username string
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started