Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 08.02.09 18:02 
Hallo,

kurze Frage: Wenn ich ein Attribut habe, wo keine Sichtbarkeit davorsteht (private, public oder protected), was setzt Java dann voraus ?
Ich nehme an, public, aber ich wollte das vor der morgigen Klausur lieber nochmal sicherstellen ;)

Ciao LHUser
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 08.02.09 18:29 
Dann besitzt diese Methode\Klasse\... Default-Sichtbarkeit, was soviel heißt wie "Innerhalb des Packages sichtbar". Genaueres findest Du bei "Java ist auch eine Insel" ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 08.02.09 18:43 
OK. Und dann ist mir jetzt noch etwas ganz komisches passiert.

Ich habe hier 2 Klassen. Es besteht keine Assoziation zwischen den beiden. Die erste hat ein Attribut public int xy; und die andere Klasse soll darauf zugreifen. Nur geht es nicht (cannot be resolved).

Was ist denn da los ????

Edit: Und wie realisiere ich in Java eine package-übergreifende Sichtbarkeit ? Ist das public ?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 08.02.09 19:24 
user profile iconLonghornUser hat folgendes geschrieben Zum zitierten Posting springen:
OK. Und dann ist mir jetzt noch etwas ganz komisches passiert.

Ich habe hier 2 Klassen. Es besteht keine Assoziation zwischen den beiden. Die erste hat ein Attribut public int xy; und die andere Klasse soll darauf zugreifen. Nur geht es nicht (cannot be resolved).

Was ist denn da los ????

Hast Du bitte etwas Quelltext dazu? Bitte genau schauen, dass die fremde Klasse auch für die einbindende Klasse sichtbar ist.

user profile iconLonghornUser hat folgendes geschrieben Zum zitierten Posting springen:
Edit: Und wie realisiere ich in Java eine package-übergreifende Sichtbarkeit ? Ist das public ?

Jap, geht mit public.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 08.02.09 19:30 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
public class Klasse1 {

public void xxx1() {
    System.out.print(xxx);
  }

}

public class Klasse2 {

public String xxx = "";

}


Hilfe :(
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 08.02.09 19:37 
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
public class Klasse1 {

public void xxx1() {
  public static void main(String[] args) {
    Klasse2 foo = new Klasse2();
    System.out.print(foo.xxx);
  }
}

public class Klasse2 {
  public String xxx = "";
}

Sollte funzen ... Du hattest ihm keine Referenz gegeben, von welcher Klasse er sich das holen soll. Und da es da eine Möglichkeit gibt, Namespaces zu verschmelzen (die ich hier nicht ausführe, da für die Allgemeinheit meist uninteressant), die entsprechende Möglichkeit ...

user profile iconLonghornUser hat folgendes geschrieben Zum zitierten Posting springen:
Hilfe :(

Nicht gleich so ausführliche Fehlermeldungen ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 08.02.09 19:42 
Aaaahhhhhh, ich bin schon total irre ;) Stimmt, man muss ja Obj.Attribut schreiben, wenn man nicht erbt. Wenn man erbt, würde die o.g. Lösung reichen (wenn also Klasse2 von Klasse1 erben würde).
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 08.02.09 19:55 
Naa, die Erklärung triffts nicht ganz ;) . In einer Klausur würde ich lieber schreiben, dass man bei Zugriffen auf this die Instanz weglassen und direkt auf Member zugreifen kann, darunter eben auch geerbte.

_________________
>λ=
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: So 08.02.09 20:37 
Du hast ja so recht ;) Das ist genauer :) Danke für den wie immer guten Support !!