public class MyApp
{
public MyApp()
{
}
public static void main(String[] args)
{
MyApp _MyApp = new MyApp();
}
}
public class OtherClass
{
public OtherClass()
{
MyApp _App = GetApp(); // ????? Gibt es so etwas ????
// es soll einfach nur das MainObject ausgespuckt werden
}
}
was ist denn das MainObject?es soll einfach nur das MainObject aufgespuckt werden
public class MyApp
{
public MyApp()
{
}
public static void main(String[] args)
{
MyApp _MyApp = new MyApp();
}
}
public class OtherClass
{
public OtherClass()
{
MyApp _App = GetApp(); // ????? Gibt es so etwas ????
// es soll einfach nur das MainObject ausgespuckt werden
}
private MyApp GetApp(){
return (new MyApp());
}
Aber das, was getApp() (Methoden werden normalerweise klein geschrieben) zurückliefert ist nicht dasselbe Objekt wie in der Main-Methode deklariert wurde.JPat hat gesagt.:Code:public class MyApp { public MyApp() { } public static void main(String[] args) { MyApp _MyApp = new MyApp(); } } public class OtherClass { public OtherClass() { MyApp _App = GetApp(); // ????? Gibt es so etwas ???? // es soll einfach nur das MainObject ausgespuckt werden } private MyApp GetApp(){ return (new MyApp()); }
so was nennt sich "Factory" ...