Java Programming
primer-original-v2mediumJava Programming03 Class And Objects, Date Apiprimer-original-v2

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; should be getBookId()
B
bookId is private
C
setBookId was not called
D
The class has no constructor

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

Explanation

Quick AnswerThe correct answer is Method getId() does not exist; should be getBookId() because it directly addresses the core logic of Java Programming.

This question has been retained as-is due to its unique context.

Related Java Programming questions

Practice more Java Programming questions

PrimerPrep has independently reviewed practice questions and coding exercises — all free.