1
public class mainPrime{
public static void main(String[] args) {
//-----------------------
new mainPrime().instancePrime2();
//------------------------
}
public void instancePrime2() {
new Prime2().iniciarJogador();
}
public class Prime2{
public void iniciarJogador() {
System.out.println("jogador iniciado!");
}
public void renderizarJogador() {
System.out.println("jogador renderizado!");
}
public void playerDeath() {
System.out.println("jogador morreu!");
}
}
}
(here in this case, I am instantiating only one Prime2 method on mainPrime, and I wanted to instantiate the entire Prime2 within mainPrime, to use the methods freely, is there any way to do this or not? I’m new to Java and I’m still learning)
"i am instantiating only one Prime2 method on mainPrime" this concept is wrong are not instantiated, only instantiate classes, that is, when making
new mainPrime().instancePrime2();
you are instantiating mainPrime and calling the instancePrime2 method. It would be the same asvar instancia = new mainPrime(); instancia.instancePrime2()
– Ricardo Pontual