DEV Community

hema latha
hema latha

Posted on

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
Enter fullscreen mode Exit fullscreen mode

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();
}
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)