Results 1 to 4 of 4
  1. #1
    R03
    R03 is offline Member
    Join Date
    Apr 2014
    Posts
    10
    Rep Power
    0

    Default How to call self method

    Hi, such as the subject.. i wanna ask how to call/define/describe self method.. below are my code :

    Java Code:
    class Exercise_1 {
    	public static void main(String[] args) {
    		banana1();
    		banana2();
    		banana3();
    		banana4();
    		banana5();
    		banana6();
    		banana7();
    		banana8();
    		banana9();
    		System.out.println("Exercise has done");
    	}
    
    	public static void banana1() {
    		System.out.println("BBBB");
    	}
    
    	public static void banana2() {
    		System.out.println("B   B");
    		banana1();
    		System.out.println("B   B");
    		banana1();
    		System.out.println();
    	}
    
    	public static void banana3() {
    		System.out.println(" AAA");
    	}
    
    	public static void banana4() {
    		System.out.println("A   A");
    	}
    
    	public static void banana5() {
    		System.out.println("AAAAA");
    		banana4();
    		banana4();
    		System.out.println();
    	}
    
    	public static void banana6() {
    		System.out.println("N   N");
    	}
    
    	public static void banana7() {
    		System.out.println("NN  N");
    	}
    
    	public static void banana8() {
    		System.out.println("N N N");
    	}
    
    	public static void banana9() {
    		System.out.println("N  NN");
    		System.out.println();
    		banana3();
    		banana4();
    		banana5();
    		banana6();
    		banana7();
    		banana8();
    		System.out.println("N  NN"); //when i try change this code to method (banana9()) i got an error
    		System.out.println();
    		banana3();
    		banana4();
    		banana5();
    
    	}
    
    }
    how exactly to call a self method ? sorry for the dumb question

    Thank you..

    Regards,
    R03.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: How to call self method

    What is a 'self method'? I know about it in the Objective C language, but I have no idea what you're talking about w.r.t. Java ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: How to call self method

    Based on his line 63:
    Java Code:
    System.out.println("N  NN"); //when i try change this code to method (banana9()) i got an error
    It looks like he is asking about how to call the method that you are currently in. He is trying to call banana9 from inside of banana9 and getting an error.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: How to call self method

    Quote Originally Posted by AlexGraal View Post
    Based on his line 63:
    Java Code:
    System.out.println("N  NN"); //when i try change this code to method (banana9()) i got an error
    It looks like he is asking about how to call the method that you are currently in. He is trying to call banana9 from inside of banana9 and getting an error.
    Ah, now I see; the OP means a 'recursive method'; if you call it unconditionally you get a stack overflow error and the JVM quits ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 6
    Last Post: 06-21-2013, 03:42 PM
  2. Why cant i call this method ?
    By TechJay in forum New To Java
    Replies: 4
    Last Post: 05-13-2013, 07:04 PM
  3. call a method from another method in same class
    By rockstaedy in forum New To Java
    Replies: 5
    Last Post: 10-03-2012, 02:42 PM
  4. Method call
    By London in forum New To Java
    Replies: 3
    Last Post: 09-15-2011, 09:02 AM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •