Java Programming
Accenture PrimermediumJava Programming3. Class And Objects, Date Api

Accenture Java Programming Practice Question

The below code snippet shows an error cannot find symbol: System.out.println("BookId:"+bobj.getId()); public class Book { private int bookId; private double bookPrice; public int getBookId() { return bookId; } public void setBookId(int bookId) { this.bookId = bookId; } public double getBookPrice() { return bookPrice; } public void setBookPrice(double bookPrice) { this.bookPrice = bookPrice; } } public class Test { public static void main(String[] args) { Book bobj=new Book(); bobj.setBookId(123); bobj.setBookPrice(500); (" " ()) System.out.println("BookId:"+bobj.getId()); System.out.println("BookPrice:"+bobj.getBookPrice()); } } Analyze the above code and select the correct reason for the error.

Answer options

A
Method getId() does not exist in Book; getBookId() should be used
B
bookId is private
C
Wrong method name called
D
Constructor missing

Correct answer: Method getId() does not exist in Book; getBookId() should be used

Explanation

The error is that getId() is not defined; the correct method is getBookId().

Related Accenture Java Programming questions

Practice more Accenture Java Programming questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.