Mit dem neuen Schlüsselwort wird ein Objekt erstellt, ohne dass eine Objektreferenz zugewiesen wird

Derzeit beziehe ich mich auf Thread-Klasse in Java. Also stieß ich auf ein Programm, in dem Objekt erstellt wird, ohne auf die Objektreferenz zu verweisen. Kann jemand das Konzept erklären

Hier ist der Code

// Create a second thread.
class NewThread implements Runnable {
Thread t;
NewThread() {
// Create a new, second thread
t = new Thread(this, "Demo Thread");
System.out.println("Child thread: " + t);
t.start(); // Start the thread
}
// This is the entry point for the second thread.
public void run() {
try {
for(int i = 5; i > 0; i--) {
System.out.println("Child Thread: " + i);
Thread.sleep(500);
}
} catch (InterruptedException e) {
System.out.println("Child interrupted.");
}
System.out.println("Exiting child thread.");
}
}

Hauptprogramm

class ThreadDemo {
public static void main(String args[]) {
new NewThread(); // create a new thread
try {
for(int i = 5; i > 0; i--) {
System.out.println("Main Thread: " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println("Main thread interrupted.");
}
System.out.println("Main thread exiting.");
}
}

Hier wird new zum Erstellen eines Threads ohne Verweis auf einen Objektverweis verwendet. Dies sollte nicht der Code sein, der diesem entspricht

NewThread ob = new NewThread (); statt nur new NewThread (); in der Hauptmethode

Antworten auf die Frage(1)

Ihre Antwort auf die Frage