Home > Java > javaTutorial > Water bottle task

Water bottle task

Patricia Arquette
Release: 2024-12-31 12:36:09
Original
194 people have browsed it

Water bottle task

  1. Create a class called WaterBottle
  2. Have below method in it. public void drink() { System.out.println("Drinking Water"); }

public class Waterbottle {

public static void main(String[] args) {
    // TODO Auto-generated method stub
Copy after login

Waterbottle glass = new Waterbottle();
glass.drink();
}
public void drink()
{
System.out.println("Drinking Water");
}
}

  1. Save and Compile this class.
  2. Create another class called Boy with main method.
  3. Inside main method, create an instance for WaterBottle class.
  4. Using created instance, call drink() method.

public class Viewer {

public static void main(String[] args) {
    // TODO Auto-generated method stub
       Tv LG = new Tv();
       LG.Watch();
}
Copy after login

}

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

source:dev.to
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