• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2521
  • Last Modified:

nested methods

public class enter{
        public static void main(String[] args){

                doNothing do = new doNothing();
        }
}
-------------------------------------------------------------------------------------------------------------
public class doNothing{
        public static String doThing(){ // not sure if this is correct

                sayHello say = new sayHello();
                return say;
        }
}
-------------------------------------------------------------------------------------------------------------
public class sayHello{
        public static void sayNow{

                System.out.println("Hello");
        }
}


how do i make the code such that i could print the word "Hello" via something like "do.doThing().sayHello()"
in the main method? Thanks
0
eturfclub
Asked:
eturfclub
  • 4
1 Solution
 
expertmbCommented:
public class enter{
        public static void main(String[] args){

                doNothing Do = new doNothing();
                Do.doThing();
        }
}

class doNothing{
        public void doThing(){ // not sure if this is correct

                sayHello say = new sayHello();

                say.sayNow();
        }
}

class sayHello{
        public void sayNow(){
                System.out.println("Hello");

        }
}
0
 
expertmbCommented:
do.doThing().sayHello()
should be
do.doThing().sayNow()
0
 
expertmbCommented:
public class enter{
        public static void main(String[] args){

                doNothing Do = new doNothing();
                Do.doThing().sayNow();
                sayHello.sayNow();
        }
}

class doNothing{
        public sayHello doThing(){
                return new sayHello();
        }
}

class sayHello{
        public static void sayNow(){
                System.out.println("Hello");

        }
}
0
 
expertmbCommented:
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now