질문 3 5점 In the following program, make the scanner receive its input from a file named temperature.txt. You may assume that this file is available in the default working path. import java.util."; public class Read { public static void main(String[] args) throws FileNotFoundException{ llyour goes here Scanner con=new Scanner(fp); 질문4 2점 Which of the following categories of methods can be used for setting values to the field variables of an object? toString() Constructors All of the above Setters and Constructors getters 질문5 3점 Which of the following statements about Object oriented programming are true? (i) The name of the object should match with the name of the class that defines the object. (ii) A constructor is a method that must accept at least one parameter and must be written every time you define a class. (iii) A constructor must have the same name as the object and has no return value. (iv) If you do not write the toString() method for the Object class nothing prints when you print the object in the test class. All of the above II I and III IV
JAVA
public class HeMan extends Skeletor { public void attack() { super.attack(); System.out.print("heman-A "); }
public String toString() { return "heman!"; } } public class SheRa { public void attack() { System.out.print("shera-A "); }
public void train() { System.out.print("shera-T "); }
public String toString() { return "shera!"; } } |
public class BattleCat extends HeMan { public void attack() { System.out.print("battlecat-A "); } public void train() { attack(); System.out.print("battlecat-T "); } } public class Skeletor extends SheRa { public void train() { System.out.print("skeletor-T "); attack(); } } |
Given the classes above, what output is produced by the following code?
SheRa[] superheros = { new Skeletor(), new HeMan(), new SheRa(), new BattleCat() };
for (int i = 0; i < superheros.length; i++) {
superheros[i].train();
System.out.println();
superheros[i].attack();
System.out.println();
System.out.println(superheros[i]);
System.out.println();
}
Provide your answers in the following blanks in the same order:
train():
attack():
superheros:
train():
attack():
superheros:
train():
attack():
superheros:
train():
attack():
superheros:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images