0

How can i do to display method shake() in my program with two class?

Display method shake() in main. https://code.sololearn.com/cjCmPNR0KdnL/?ref=app

24th Apr 2020, 7:20 AM
Malick Diagne
Malick Diagne - avatar
2 Respuestas
+ 2
Person Ho = new Person (); Person.Hand Ha = Ho.new Hand (); Ha.Shake (); Also in your Shake() method, System needs to be capitalized.
24th Apr 2020, 7:34 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg answer is correct. Another option is to create a method to return a Hand object from Person object. public class Person { private Hand hand = new Hand(); public Hand getHand() { return hand; } public class Hand { void Shake () { System.out.println ("Hi"); } } } public class Program { public static void main(String[] args) { Person p = new Person(); p.getHand().Shake(); } }
24th Apr 2020, 7:51 AM
Chris Persichetti
Chris Persichetti - avatar