Question
JAVA PROGRAMING QUESTIONS 1. Write a constructor for a class named Point. The constructor has two double parameters xVal and yVal. The constructor sets the
JAVA PROGRAMING QUESTIONS
1. Write a constructor for a class named Point. The constructor has two double parameters xVal and yVal. The constructor sets the xCoord and yCoord fields.
2. Given the code below, which statement is true?
Train train1 = new Train(); Train train2; Train myTrain; train2 = new Train(); myTrain= train1; A) train1 and train2 refer to valid objects
B) train1 and myTrain refer to the same object
C) train2 and myTrain refer to the same object
A | ||
B | ||
C | ||
A & B | ||
A & C | ||
B & C | ||
A & B & C | ||
none of the above |
3. Given a class Spaceship with private field numYears and method:
public void addNumYears(int numYears)
In the class SpaceshipMain the main method has the variable definition: Spaceship ss1 = new Spaceship().
Which of the following adds 5 to ss1's numYears?
a. ss1.numYears += 5; | ||
b. this.numYears += 5; | ||
c. this.addNumYears(5); | ||
d. ss1.addNumYears(5); |
4. Given a class Spaceship with private field numYears and method:
public void addNumYears(int numYears)
In the method, which would set field numYears to 0?
a. numYears = 0; | ||
b. numYears = numYears; | ||
c. this(numYears) = 0; | ||
d. this.numYears = 0; |
5. Write the header (first line) of a default (no-arg) constructor for the class named Train, ending with {.
6. Write the header (the first line) for a non-static public method named setSalary, having parameter int salaryAmount, and returning void, ending with {.
7. Define a private field named numChildren of type int. Do not assign any value.
8. Write the header (first line) of a class definition for a class named Train, ending with {. (It should be a public class)
9. he RunnerInfo class has a member method setTime. Object runner1 is of type RunnerInfo. Type a statement that sets runner1's time to 100.
10. The + in a UML diagram indicates additional private items.
True or False
11. Given the following primitive wrapper objects, which of the comparisons below are true:
Integer score1 = new Integer(95); Integer score2 = new Integer(91); Integer score3 = 95; int maxScore = score1;
A) score1 < score2
B) score1 == score3
A | ||
B | ||
A & B | ||
none of the above |
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