Results 1 to 11 of 11
Thread: understanding class
- 07-26-2011, 01:17 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
understanding class
Hi everybody........
Please make me understand of the following program line by line, basically from line 8.
class Program21_21 {
public void m(){
System.out.println("m method in Program21_21 class");
}
}
public class Program21{
public Program21_21 m(){
return new Program21_21(){
public void m(){
System.out.println("m method in Program21 class");
}
};
}
public static void main(String args[]){
Program21_21 obj = new Program21().m();
obj.m();
}
}
output is -- m method in Program21 class
this program is not clear to me.
Thanks.........
- 07-26-2011, 01:29 PM #2
Who wrote the code?
db
- 07-26-2011, 01:31 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
output is -- m method in Program21 class
- 07-26-2011, 01:36 PM #4
Which method prints that message?
- 07-26-2011, 01:43 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
- 07-26-2011, 01:48 PM #6
What class does the obj variable refer to? Which method will be called in main?
- 07-26-2011, 01:58 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
- 07-26-2011, 02:02 PM #8
Here's a rewrite that should do the same thing:
Java Code:// output is -- m method in Program21 class public class TestInheritance { static class Program21_21 { public void m(){ System.out.println("m method in Program21_21 class"); } } static class Program21{ // a method public Program21_21 method(){ // Create new object and return it return new Program21_21(){ @Override public void m(){ System.out.println("m method in Program21 class"); } }; } } // end class public static void main(String args[]) { Program21 pgm21 = new Program21(); // create an instance Program21_21 obj = pgm21.method(); // call a method to get another object obj.m(); // call a method on new object } // end main } // end class Test....
- 07-26-2011, 02:16 PM #9
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
Thanks for ur help.
But could u explain me actually what happen in these code ---
static class Program21{
// a method
public Program21_21 method(){
// Create new object and return it
return new Program21_21(){
@Override
public void m(){
System.out.println("m method in Program21 class");
}
};
}
} // end class
- 07-26-2011, 02:22 PM #10
There is a class, the class has a method, the method returns a reference to another class.
- 07-26-2011, 02:24 PM #11
Member
- Join Date
- Jun 2011
- Posts
- 59
- Rep Power
- 0
Similar Threads
-
Problem understanding class statement.
By martijnburger in forum New To JavaReplies: 3Last Post: 07-21-2011, 11:07 PM -
Need some understanding and help!
By Kevinius in forum New To JavaReplies: 8Last Post: 05-14-2011, 05:50 AM -
Understanding -- new Class() -- syntax.
By AcousticBruce in forum New To JavaReplies: 8Last Post: 12-14-2010, 12:53 AM -
Having trouble understanding Class Graphic
By Bernard Robitaille in forum JCreatorReplies: 1Last Post: 04-18-2009, 02:55 AM -
Understand my logic errors and better understanding method and class creation
By freethinker89 in forum New To JavaReplies: 3Last Post: 10-06-2008, 11:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks