Question: 1. State whether the given statement is true or false. If false explain why? Variables declared in the body of a particular method are known

 1. State whether the given statement is true or false. If

false explain why? Variables declared in the body of a particular method

are known as instance variables and can be used in all methods

of the class. [02 Marks] 2. How getters and setters are useful?

1. State whether the given statement is true or false. If false explain why? Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class. [02 Marks] 2. How getters and setters are useful? [04 Marks) 3. Write the output in the space provided for the given code Page 2 of 8 Object Oriented Programming PROGRAMMING CS102 public class Outputl{ public class Output1Test { public int x; public static void main(String[] args) { public double // TODO Auto-generated method stub y; Output1 ol = new Output1(); } ol.y = 10; Output1 o2 = new Output1(); 02.x = 5; Output1 o3 = new Output1(); 03.x = 02.x++; 03.y = ++o1.y; System.out.println(01.x + ol.y + o2.x + 02.y + 03.x + 03.y); } } 4. Write the output in the space provided for the given code public class Output2 { private int x; private double y; public Output(int xl) { x= xl; } public Output2(int x1, double yl) { x = xl; y = yl; } public int getX() { return x; } pub double getY() { return y; } Page 3 of 8 Object Oriented Programming PROGRAMMING CS102 public class Output2Test { public static void main(String[] args) { // TODO Auto-generated method stub Output2 01 = new Output2(10); Output2 o2 = new Output2(20, 30); System.out.println(01.getX() + 01.getY() + 02.getX() + o2.getY()); } } [1.5 Marks) 5. Explain why the following program is giving error at line 4 from class Sum.java and error at lines 5 and 6 from the class "Sum Test.java"? How can we resolve the error? 6 1 public class Sum 2 private int x; 3 private double y; 49 public display() { 5 System.out.println("X = " + x); System.out.println("Y=" + y); 7 } 8} 1 public class Sum Test { 2e public static void main(String[] args) { // TODO Auto-generated method stub Sum s = new Sum(); 5 s.y = 23.67; s.display(); 7 } 3 4. 6 8 [04 Marks) 6. Draw an UML diagram for given problem statement. a. It has three instance variables year Model of type int, make of type String and speed of type double. b. Provide a constructor that initializes the instance variables. c. Write getter methods for the instance variables of the class. d. Provide a method accelerate, which adds 12 to speed field each time it is called. e. Provide a method brake, which subtracts 10 to speed field each time it is called. [07 Marks] 7. Write the JAVA program by the using the problem statement which is given in Q6. Write a test class name CarTest and perform the following. a. Create an object for the class Car with the following data yearModel = 2020, make = "Ford Explorer and speed = 10 b. call the method accelerate for 10 times using the loop c. call the method brake for 7 times using the loop. d. Display car information as shown in output. Page 6 of 8 bject Oriented Programming PROGRAMMING CS102 Car Information Model Year = 2020 Car Make = Ford Explorer Speed of the Car = 60.00 KMPH

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!