r/learnjava • u/[deleted] • Dec 08 '17
Calling methods of a different class query
Hi guys.
Say I have a method in class A.
I then wish to call the method from class A in public static void main(String[] args).
How would I do so?
3
u/empire539 Dec 08 '17
If the method is non-static, then you probably will need to instantiate an A object first, e.g.
A a = new A();
a.myMethod();Otherwise, if the method is static, you should be able to call it directly on A: A.myStaticMethod().
1
u/koproller Dec 08 '17
Can't you also make singleton?
4
u/that_one_dev Dec 09 '17
Do you mean something like this?
Singleton.getInstance().someMethod()
That would be fine but I don't think someone who doesn't understand objects and methods should be worried about a singleton just yet
-1
Dec 08 '17
Oh, yeah forgot about that....thanks! :)
4
u/that_one_dev Dec 09 '17 edited Dec 09 '17
I don't think you know what a singleton means if you don't know how to call a method
6
u/throwaway_for_cause Dec 08 '17 edited Dec 08 '17
Have you ever considered doing a tutorial instead of flooding (6 posts in the last 24 hours) the subreddit?
The sidebar here has some of the best Java tutorials in existence in the Free Tutorials section.
You will need a lot more than a couple reddit posts can fill. Take a proper tutorial and learn the correct way.
The MOOC Object Oriented Programming with Java (sidebar) will teach you what you are lacking.
-8
Dec 08 '17
[removed] — view removed comment
7
u/override_acid Dec 08 '17
No need to be a dick about a valid suggestion.
You have huge gaps in your knowledge that you need filled, so suggesting a tutorial is the appropriate way to go.
This is not the first time you blow up to a perfectly valid comment. You should reconsider your attitude.
You are flooding the subreddit. There is no discussion about that. Flooding is against the Reddit Terms of Service and against the reddit rules about spamming, even if your questions are pertaining to Java and valid.
-4
Dec 08 '17
You condemn me for my attitude, and yet choose to use curse words? You do realise that also is a clear violation of the Reddit Terms of Service, specifically concerning:
Unwelcome content as well Do not threaten, harass, or bully, in addition to vulgar, harrassing and or offensive.
Perhaps you should follow the rules yourself, before so prissily demanding that of others.
5
u/override_acid Dec 08 '17
Telling you that you behave like an asshole and a dick is neither threatening, nor harassing, nor bullying. It's simply calling you out on your inappropriate behavior that you continue to display.
This has nothing to do with the reddit TOS because I was not calling you this, I was stating that you behave like one - which is a completely different context and meaning.
6
Dec 08 '17
These are the people that are going to be taking time out of their day to help explain something to you. I would suggest being more respectful rather than saying the equivalent of "you aren't a mod, pound sand".
3
u/desrtfx Dec 09 '17
Ahem... https://i.imgur.com/P7qEUPW.png
/u/throwaway_for_cause is a moderator and even if he weren't, he could still state his opinion without you having even the slightest right to go against him.
You are again misbehaving and have been in the entire thread. If you don't learn to properly behave yourself and stop your constant threatening and reporting, you will face consequences.
Even your mail to the moderators was inappropriate. Moderators have full rights how to run their communities and full responsibility. They can do in their communities basically what they want.
Your behavior is unacceptable, and you have been called out by members of the community who are here longer than you are. It is their full right to call you out when you're misbehaving. Moderators or not. Instead of going against those people, you should accept what they are telling you and change your attitude.
A single more step out of line will get you permanently banned.
You don't need to report this as offensive, abusive, or threatening. I'm just stating facts and warning you.
-4
Dec 08 '17
[removed] — view removed comment
5
u/override_acid Dec 08 '17
Have you considered I have DONE a tutorial, and yet still struggled to grapple with the concepts of it?
Well, even then, the suggestion is perfectly valid and doesn't give you a permit to behave like an asshole. If a single tutorial is not sufficient, do another one, and another, and another until you understand it.
6
u/[deleted] Dec 08 '17
Since this is a homework assignment, and, as other users have stated, you are needlessly flooding the subreddit, please read your coursebook and finish the tutorials in the sidebar.
It is simply impossible to not grasp the concept of methods, scopes, getters/setters and private/public fields after finishing the MOOC.
Please don't be ignorant.