Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to call a method which is present in different class but having a same package. Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

In able to do that, we need to create an instance on another class as:

B b=new B();

b.method();

Or, can create a static method in class like:

class B

{

 static void staticMethod();

}

And then, we can call like this:

B.staticMethod();

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners :

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...