Home >Java >javaTutorial >Water bottle task

Water bottle task

Patricia Arquette
Patricia ArquetteOriginal
2024-12-31 12:36:09179browse

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

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();
}

}

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

Statement:
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