007-003-008
Class Fields: Book Class
Medium
Problem Description
Class Fields: Book Class
In this problem, you will define a Book class with title and pages fields that can be accessed externally.
Learning Objective: Understand how to define fields in a class and store different values for each instance
Overview
Create a Book class representing book information. Define title and pages as fields.
Specifications
- Define following fields in Book class
String title(book title)int pages(page count)
- Fields must be directly accessible via instances
- No constructors or methods required
Verification
Your class will be tested by creating instances and setting field values:
Book book = new Book();
book.title = "Java Programming";
book.pages = 350;
System.out.println("Title: " + book.title);
System.out.println("Pages: " + book.pages);
Expected output:
Title: Java Programming
Pages: 350
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up