Ich habe eine 2 Java-Klassen eine mit Hauptmethode und eine mit privaten Variablen & Methoden zum Abrufen und Einstellen. Also, meine Frage ist, können wir die gleiche Objektreferenzvariable in allen Setter (3 Setter) und eine andere Referenzvariable in allen Gettern (3) verwenden? Ich habe das benutzt und ich habe null Wert.Doppelte Referenzvariable in Java
Aber wenn ich 3 verschiedene Objektreferenzvariablen für 3 Getter und die gleiche 3 Objektreferenzvariable für Getter verwende, dann hat es funktioniert. Also, kann mir jemand dieses Konzept erklären?
Paket project1;
public class Encapsulationjerry1 {
public static void main(String[] args)
{
System.out.println("Now, we are gonna test our Encapsulation");
// I gave different variables for all setters and same respective variables for getters. This is working fine.
Encapsulationtom1 obj1 = new Encapsulationtom1();
Encapsulationtom1 obj2 = new Encapsulationtom1();
Encapsulationtom1 obj3 = new Encapsulationtom1();
obj1.setDesignation("Lead Designer");
obj2.setEmployeeId(23452);
obj3.setEmployeeName("Meliodas");
System.out.println("The designation is "+ obj1.getDesignation());
System.out.println("The Employee Id is "+ obj2.getEmployeeId());
System.out.println("The Employee Name is "+ obj3.getEmployeeName());
// But when i give same variable to all setters and a different variable to all getters, it gave me null value. WHY?
}
}
Lässt etwas Code sehen. – ApolloSoftware
Ein gutes Code-Beispiel sagt mehr als tausend Worte ... – assylias
http://paste.ofcode.org/9KEX2aWbKNKD3wcsL4J8HQ sein pasteof.code Link: D –