Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:27:52+00:00 2026-06-06T02:27:52+00:00

I am not sure if the title is accurate. I have several classes like

  • 0

I am not sure if the title is accurate. I have several classes like Tv and I want to use all of them in only one class. Is it possible to call the methods in Tv in another class? If so, do I need to revise the constructor in class Tv? (TS is an interface).

class Tv implements TS{

    private String v;

    public Tv(String v){
            this.v = v;
    }

    public void open(){
            System.out.println("open");
    }

        public void volume(String v){
        ...
        }

}

public class TvSet{
    public static void main(String args[]){
        Tv t = new Tv("+");
    }
}

I have tried this:

public class RunTv {
    Remote r = new Remote("+");
    Tv t = new Tv("+");
    t.open();
}

The IDE reminds me “identifier expected after this token.” Should I modify Tv or RunTv?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:27:54+00:00Added an answer on June 6, 2026 at 2:27 am

    The first problem is already answered by Owl and Roddy of the Frozen Pea, but to summarize: Yes you can call methods in another class as long as they are public and you have an instance of the class containing the method.

    For your other problem with the “identifier expected...” error, you should change RunTv.

    You cannot call t.open() outside a method block. If you changed it to something like this:

    public class RunTv {
        public void openNewTv()
        {
           Remote r = new Remote("+");
           Tv t = new Tv("+");
           t.open();
        }
    }
    

    Then whenever you call the openNewTv method it will create a new instance of Remote and Tv and it will then call the open method in the Tv instance. To call openNewTv you could create an instance of RunTv in your main method like this:

    public class TvSet{
        public static void main(String args[]){
            Tv t = new Tv("+");
            RunTv runTv = new RunTv();
            runTv.openNewTv();
        }
    }
    

    If you do not want to create a new instance every time you have to open a new Tv you could make the method static, which means it will not belong any instance, but rather the class itself (To understand these things better, you should read this)
    You can make the method static like this:

    public class RunTv {
        public static void openNewTv()
        {
           Remote r = new Remote("+");
           Tv t = new Tv("+");
           t.open();
        }
    }
    

    Now you can call openNewTv without having to create an instance of RunTv like this:

    public class TvSet{
        public static void main(String args[]){
            Tv t = new Tv("+");
            runTv.openNewTv();
        }
    }
    

    Hope this helps. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure how to even phrase the title on this one! I have the
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
I am not sure my title is correct or not since I have no
First of all, I'm not sure if the title accurately describes what I'm referring
Not entirely sure my question title describes what I want to do, but couldn't
As the post title implies, I have a legacy database (not sure if that
I'm not sure if the question title is accurate... Let me start by explaining
Not sure if my title is worded well, but whatever :) I have two
Not sure what the correct title for this question should be. I have the
I'm not sure the title is accurate, please feel free to rename the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.