Home > Java > javaTutorial > book task

book task

Susan Sarandon
Release: 2025-01-05 01:00:38
Original
358 people have browsed it

book task

  1. Create a class called 'Book'.
  2. Have below method in Book class. public void read(int page) { System.out.println("No. of Pages " page); }
  3. Create one more class called 'Reader' with main method.
  4. Create instance for Book class now.
  5. Using your instance, call read() method and pass 100 as argument.

public class Book {

public static void main(String[] args) {
    // TODO Auto-generated method stub
Book physics = new Book();
physics.read(100);
}
public void read(int page)
{
System.out.println("No. of Pages " + page); 
}
Copy after login

}

public class Reader {
public static void main(String[] args)
{

Book physics = new Book();
physics.read(100);

}

}
out put ---No. of Pages 100

The above is the detailed content of book task. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template