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
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.
+ 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();
}
}