Page 1 of 1

а Will the following code from a file called "student.java" compile? If not, then why? public class Student { private in

Posted: Sun May 15, 2022 12:27 pm
by answerhappygod
 1
1 (114.62 KiB) Viewed 83 times
 2
2 (82.2 KiB) Viewed 83 times
а Will the following code from a file called "student.java" compile? If not, then why? public class Student { private int id; private String name; public Student(int id, String name) { this.id = id; this.name name; } = = = = public void setId(int i) {id = i;} public void setName(String n) {name = n; } } public int getId() {return id;} public String getName() {return name;} } No, the whitespace around the getter and setter methods is incorrect. No, the class name must match the file name. o No, the "this" keyword is missing in the getter and setter methods. Yes, it will compile. o No, there is a missing }.

What is wrong with the following code? public class Main { public boolean checkOdd(int a ) { return a % 2 1; } public static void main(Strin g[] args) { for(int i=0; i<10; i++) { if(checkOdd(i)) { System.out.printl n(i+" is odd!"); } } } o There is an incorrect number of opening and/or closing brackets. The checkOdd method is not called properly. O A variable is used that has not been declared. o A semicolon is missing.

If you have a private method called calculateTotal() in ReceiptClass, how would you call this method on an object of ReceiptClass called myReceipt? o calculateTotal(); o myReceiptClass.calculateTotal(); o myReceipt cannot call the calculateTotal() method. Calling this method will result in a compiler error o myReceipt cannot call the calculateTotal() method. Calling this method will result in a runtime error. o myReceipt.calculateTotal();