Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

I was trying to import class and I have created a program to get the messages but it is not working, below is the code:

class Test {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        Message messageObject = new Message ();

        Time timeObject = new Time ();

        System.out.println("Enter your message here: ");

        String message = input.nextLine();

        messageObject.simpleMessage(message);

        timeObject.getTime();

    }

    void simpleMessage(String message) {

        System.out.println(message + time);

    }

}

Error :

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 

Message cannot be resolved to a type

Message cannot be resolved to a type

The constructor Time() is undefined

at Test.main(Test.java:8)

Can anyone help me with this?

2 Answers

0 votes
by (26.7k points)

Basically, this error shows up because the Message class is not available while compilation. In able to rectify the error you need to import the message class like:

import package1.package2.Message;

I hope this will help.

Want to become a Java expert? join Java Course now!!

0 votes
by (37.3k points)

class Test {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        Message messageObject = new Message ();

        Time timeObject = new Time ();

        System.out.println("Enter your message here: ");

        String message = input.nextLine();

        messageObject.simpleMessage(message);

        timeObject.getTime();

    }

    void simpleMessage(String message) {

        System.out.println(message + time);

    }

}

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...