- Create a class called TV
- Have below method in it. public void watch() { System.out.println("Watching TV"); }
- Save and Compile this class.
- Create another class called Viewer with main method.
- Inside main method, create an instance for TV class. (Instance - object)
-
Using created instance, call watch() method.
public class Tv {public static void main(String[] args) {
// TODO Auto-generated method stub
Tv LG = new Tv();
LG.Watch();
}
public void Watch ()
{
System.out.println("watching tv");
}
}
public class Viewer {
public static void main(String[] args) {
// TODO Auto-generated method stub
Tv LG = new Tv();
LG.Watch();
}
}
out put watching tv
Top comments (0)