Question
QUESTION 11 Consider the following Java code fragment. What number is printed? int total = 0; for (int i=1; i
QUESTION 11
Consider the following Java code fragment. What number is printed?
int total = 0; for (int i=1; i<=5; ++i) { for (int j = 1; j <= 5; ++j) { total = total + 1; } } System.out.println(total);
4 points
QUESTION 12
Consider the following Java code fragment:
public class MyClass { public int x; public int y; }
This class is syntactically correct, but violates principles of object oriented programming. What is wrong with this class?
a. | Fields are public rather than private | |
b. | The class should be declared private class MyClass | |
c. | No character coding has been specified | |
d. | All of the above |
4 points
QUESTION 13
Which of following pairs have an is-a relationship?
a. | Circle and Shape | |
b. | Shape and Location | |
c. | Circle and Square | |
d. | Circle and Location |
4 points
QUESTION 14
Consider the following code fragments:
public class PhoneNumber { private int areaCode; private int prefix; private int lineNumber; // Constructor public PhoneNumber(int areaCode, int prefix, int lineNumber) { this.areaCode = areaCode; this.prefix = prefix; this.lineNumber = lineNumber; } // Accessors go here (not shown in this example) } public class InternationalPhoneNumber extends PhoneNumber{ private int countryCode; // TODO Add Constructor }
The first line of the constructor for InternationalPhoneNumber should be:
a. | public InternationalPhoneNumber(int areaCode, int prefix, int lineNumber) { | |
b. | public InternationalPhoneNumber(PhoneNumber phoneNumber, int countryCode) { | |
c. | public InternationalPhoneNumber(this.all) { | |
d. | public InternationalPhoneNumber(int areaCode, int prefix, int lineNumber, int countryCode) { |
4 points
QUESTION 15
Look at the Java code fragment in Question 14. The second line of the constructor for InternationalPhoneNumber should contain:
a. | super(); | |
b. | super(areaCode, prefix, lineNumber); | |
c. | super(areaCode, prefix, lineNumber, countryCode); | |
d. | super(this); |
3 points
QUESTION 16
Look at the Java code fragment in Question 14. The InternationalPhoneNumber constructor must also contain:
a. | this.countryCode = countryCode; | |
b. | this.countryCode = this.countryCode; | |
c. | countryCode = this.countryCode; | |
d. | return(countryCode); |
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