In the main method of FanTest class, write the java code to get and print the value of speed, given that the object name is fan1.a.System.out.println(fan1.setSpeed());b.System.out.println(fan1.getSpeed(int speed));c.System.out.println(fan1.getSpeed(speed));d.System.out.println(fan1.getSpeed());
Question
In the main method of FanTest class, write the java code to get and print the value of speed, given that the object name is fan1.a.System.out.println(fan1.setSpeed());b.System.out.println(fan1.getSpeed(int speed));c.System.out.println(fan1.getSpeed(speed));d.System.out.println(fan1.getSpeed());
Solution
The correct way to get and print the value of speed from the object fan1 in Java is:
System.out.println(fan1.getSpeed());
So, the correct option is d. System.out.println(fan1.getSpeed());
Here's why:
a. System.out.println(fan1.setSpeed()); is incorrect because setSpeed() is a method to set the value of speed, not to get it.
b. System.out.println(fan1.getSpeed(int speed)); is incorrect because getSpeed() method does not take any arguments.
c. System.out.println(fan1.getSpeed(speed)); is incorrect because getSpeed() method does not take any arguments.
d. System.out.println(fan1.getSpeed()); is correct because getSpeed() is a method to get the value of speed and it does not take any arguments.
Similar Questions
The speed(ω) - torque(T) characteristics of a fan type load is given byans.T ∝ ωT ∝ 1/ωT = constantT ∝ ω2 Previous Marked for Review Next
Variable Fan Speed Control
You want to compare the energy efficiency of two electric fans. For every 100 J of electrical energy supplied:Fan 1 produces 60 J of kinetic energy, 30 J of heat and 10 J of sound.Fan 2 produces 85 J of kinetic energy, 10 J of heat and 5 J of sound.Determine which fan is more efficient.Fan 1Fan 2
correct answerPredict the output of following Java Programs.public class Physics extends Thread { public static void main(String[] args) { try { Thread t = new Thread(new Physics()); Thread t2 = new Thread(new Physics()); } catch (Exception e) { System.out.print("e "); } } public void run() { for (int i = 0; i < 2; i++) { try { Thread.sleep(500); } catch (Exception e) { System.out.print("e2 "); } System.out.print(Thread.currentThread().getName()+ " "); } }}Optionseno outpute2compilation fails
Check the following Java program carefully. What should be written in the blank? Choose from the given options. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static ________ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; }}Group of answer choicesvoidStringintchar
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.