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

}

原文链接:Water bottle task

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容