Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Call a method

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Thanked 0 Times in 0 Posts

    Unhappy Call a method

    Quote Originally Posted by Rauda View Post
    public class Clock {
        private int hr;
        private int min;
        private int sec;
        public int getHour() {
            return hr;
        public void setHour(int h) {
            if (h >= 0 && hr <= 23) {
                hr = h;
        public int getMin() {
            return min;
        public void setMin(int m) {
            if (m >= 0 && min <= 60) {
                min = m;
    private void tick() {
            if (sec == 60) {
                sec = 0;
                if (min == 60) {
                    min = 0;
                    if (hr == 24) {
                        hr = 0;
    I'm so sorry for this
    & i know that I'm should to write my own question

    but can you tell me how can I call this method on the main method plzzz gelp me

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,465 Times in 2,416 Posts

    Default Re: Call a method

    Question moved to new thread.

    how can I call this method
    To call a method in a class, get an instance of the class and use the dot notation to call the class:
       referenceToClass.theMethodToCall(); // call theMethodToCall

    One way to get a reference to an instance of the class is to use a new statement:
     SomeClass referenceToClass =  new SomeClass();    // create instance of SomeClass
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Cannot call method because it is non-static
    By thegorila78 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 7th, 2013, 01:19 PM
  2. Only if one method is true does it call the other?
    By ColeTrain in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2012, 03:28 PM
  3. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  4. Call method(s) within the same class
    By mwr76 in forum Object Oriented Programming
    Replies: 8
    Last Post: September 26th, 2011, 12:58 AM
  5. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM