- Create a class called WaterBottle
- 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");
}
}
- Save and Compile this class.
- Create another class called Boy with main method.
- Inside main method, create an instance for WaterBottle class.
- 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();
}
}
Top comments (0)