Home > Java > javaTutorial > Tv task

Tv task

Mary-Kate Olsen
Release: 2025-01-05 06:56:39
Original
832 people have browsed it

Tv task

  1. Create a class called TV
  2. Have below method in it. public void watch() { System.out.println("Watching TV"); }
  3. Save and Compile this class.
  4. Create another class called Viewer with main method.
  5. Inside main method, create an instance for TV class. (Instance - object)
  6. 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();

}
Copy after login

}
out put watching tv

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

Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template