public class InnerEx7 {
public static void main(String[] args) {
Foo foo=new Foo();
Foo foo2=foo.stam(55);
foo2.print();
}
}
class Foo{
String word="bye";
void print(){} // what does this fucntion do. why do i need it if it is empty
public Foo stam(final int x){
final int y=10;
class Inner extends Foo{ // why do i need to use inheritance here?
public void SayHello() {
System.out.println("Hello");
}
@Override
void print() {
System.out.println(y*x);
System.out.println("Print "+word );
}
}
Inner inner=new Inner();
inner.SayHello();
return inner;
}
}
NewOrder
-1
Posting Whiz
Recommended Answers
Jump to PostWhat happens when you try to compile it without the extension?
Jump to PostSorry - no time now. I was wrong - that IS an anonynmous inner calss. I;ll post more in th emorning.
Jump to Postback online now. Sorry about the error in my previous post. It was only the first word that was wrong. Replace it with Yes and the post is OK.
The new Person(d)... code is an anonymous inner class.
Its syntax works just like the example I described line-by-line yesterday, …
Jump to PostThank you very much indeed James. Thank you for your comments. I will try the method getActionListeners() to have a taste in getting a reference to an instance of an anonymous inner class . I am also noticed that the return data type of the method is an array: public …
Jump to PostShould be fine. If youy only add 1 listener it should be in [0] of the array.
ps: Although you don't give the class a name, the compiler generates one by adding $1 (etc) the the outer class name. You will see these in the generated .class files.
All 28 Replies
NormR1
563
Posting Sage
Team Colleague
NewOrder
-1
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
NewOrder
-1
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
NewOrder
-1
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
NewOrder
-1
Posting Whiz
tong1
22
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
tong1
22
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewOrder
-1
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewOrder
-1
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewOrder
commented:
thanks for helping
+0
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewOrder
-1
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
tong1
22
Posting Whiz
NewOrder
-1
Posting Whiz
tong1
22
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
tong1
22
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
tong1
22
Posting Whiz
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NewOrder
-1
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.