473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read this program

40 New Member
package Anonymous;

class Base
{
public void m1(){
System.out.println("base m1 called");
}

}


package Anonymous;

class AnonymousTest
{
public static void main(String[] args)
{
Base b=new Base(){
public void m1(){
System.out.println("anonymous m1 called");
}
public void m2(){
System.out.println("anonymous m2 called");
}
{
System.out.println("instane initializer called");
}
};
b.m1();
}
}


Can any body explain abt this program
Oct 30 '07 #1
7 1317
r035198x
13,262 MVP
1.) Please use code tags when posting code.
2.) Which part do you want explained? Have you run it to see what the output is?
Oct 30 '07 #2
gsreenathreddy
40 New Member
Expand|Select|Wrap|Line Numbers
  1. package Anonymous;
  2.  
  3. class Base
  4. {
  5. public void m1(){
  6. System.out.println("base m1 called");
  7. }
  8.  
  9. }
  10.  
  11.  
  12. package Anonymous;
  13.  
  14. class AnonymousTest
  15. {
  16. public static void main(String[] args)
  17. {
  18. Base b=new Base(){    //explain here
  19. public void m1(){
  20. System.out.println("anonymous m1 called");
  21. }
  22. public void m2(){
  23. System.out.println("anonymous m2 called");
  24. }
  25. {
  26. System.out.println("instane initializer called");
  27. }
  28. };
  29. b.m1();
  30. }
  31. }
Oct 30 '07 #3
JosAH
11,448 Recognized Expert MVP
Just posting the code again isn't going to help you much. Did you compile and
run the code?

kind regards,

Jos
Oct 30 '07 #4
gsreenathreddy
40 New Member
Yes,

I had compiled and run the application and got the output as

iinstane initializer called
m1 is called.
Oct 30 '07 #5
r035198x
13,262 MVP
Yes,

I had compiled and run the application and got the output as

iinstane initializer called
m1 is called.
What did you expect as the output?
Oct 30 '07 #6
gsreenathreddy
40 New Member
I would like what happens internally
Oct 30 '07 #7
JosAH
11,448 Recognized Expert MVP
Yes,

I had compiled and run the application and got the output as

iinstane initializer called
m1 is called.
*Which* m1 is called?

kind regards,

Jos
Oct 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
3
by: lpe540 | last post by:
Hi, I'm having trouble using istream to read in a file in its entirety on UNIX. I've written a dummy program that essencially reads in a file from stdin and writes it out to a file. When I cat a...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
4
by: kj | last post by:
I consider myself quite proficient in C and a few other programming languages, but I have never succeeded in understanding a largish program (such as zsh or ncurses) at the source level. ...
2
by: Rajen | last post by:
Suppose the field length is 25 characters. After entering the 25th character, it should be available to process. Program should not wait for the user to press enter/return key. Thank you.
0
by: heplesser | last post by:
Summary: Does the C++ standard require std::basic_istream<>::operator>>(double&) to leave the input stream untouched in case of a read failure? Details: I noticed an unexpected behavior of...
1
by: Matrixinline | last post by:
Hi All, File Text.txt Contains following text as : "C:\program file\application data\details\app" "D:\Program File" I tried to read that data as fscanf(oFp, "%s %s", sCopyDirectory,...
5
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.