Originally posted by Bhaswati Karmakar:
In order to override a method, what are things that should be taken into consideration ?
Thanks
Originally posted by Navin Jain:
hi got this idea from puneites.
really we mumbaites should also develop such a forum to make the
things easier.
pls let me know if u r frm mumbai and appearing for the exam in feb or march.
Originally posted by Golam Newaz:
Hi,
In your example:
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
});
// new WindowAdapter(). It says to compiler" Create an instance
of a new, unamed class which implements the WindowListener
interface...
Look here you are making an instance using new but without any object referece name . So it is unnamed class. So abstract
can be anonymous class.
Whatever you say after the "new" as in "new Something()", if Something is an interface, then the anonymous
class implements that interface (and must define all the
methods of that interface). But if Something is a class,
then your anonymous class automatically becomes a subclass of that class. This is perfect for the event adapter
classes like WindowAdapter.
- Golam Newaz
Originally posted by Navin Narayan:
Guys, like you all, I am also giving the Java Certification.
The Mughal Khalid exam is good but it does not give answers. So
I modified it a bit so that it displays answers too. If anyone is interested, you all can mail me.
Originally posted by Peter Tran:
[B]Bhakti,
In your example, you're instantiating an anonymous class from the WindowAdapter class and you provide an override method for the windowClosing method. This is perfectly fine, because you are not keeping a reference of the WindowAdpater class around.
E.g.
The second example is fine, because I'm creating a reference to an anonymous class. Remember, that this anonymous class is a concrete class because I'm providing an implementation for one of the methods in the WindowAdapter class.
I hope this makes sense. I realize the concept is confusing, and takes some getting use to.
-Peter[/B]
Originally posted by Rajpal Kandhari:
Hello Ajith & Eveyone out here:
If code is like below,
String str="First";
str="Second";
str="Third";
str="Four";
Then after line 4, 3 objects will be eligible for Garbage Collection.
Should we conside this as the bottom line:
"How the string object is created (with new or without new) has no effect on Object eligible for GC."
Pls help us out.
Originally posted by Jane Griscti:
Arvind,
Looks as if Manfred is right ... you found a 'bug'.
There is something very similar reported in the Sun Bug database compile-time constants not used correctly for 'unreachable statements'
It reportedly does not occur in JDK 1.3
Hope that helps
Originally posted by krishnashu:
[B]I could not get the right answer for my question
why the following code works
[/B]
Originally posted by atin sehgal:
Hi!
There are a few things which i think I shd share with u first so that i am able to convince u.
1) The mofdifier.The modifier here is defaulty ansd not public.
2) Classs level whether top level or anyother..
If the modifier is public and class is top level its a necessary condition that for compiling that
a) Source Name shd be same as class name
For efficient running(no run time error_)
a) Main method shd b perfect.
Now the case of yr example..
Your class has no access modifir => it translates to friendly or default access.
Hence the condition for efficient compiling in this case is that
1) source file != name of class file.
they can be different.. and yet compile.
For running the condition ois :
That main method shd be correct..
Feel free to touchbase if any query.
I am attching a program that i have done today itself...
//top level class with default access modifier.Class compiles.It will not compile only when main method is not perfect
class abc /* this class will compile even if the file name is different from source file name*/
//class firstdefault//I saved the file earlier as firstdefault.java/.Then changed the name to a different source name.Still it compiled...
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
/* So conclusion...if a class file is having default access modifier , we can compile the class successfully
a) Even if source name different...from class name.
Runs successfully
a)only if main is absolutely correct.
Plz revert in case of doubt or anything wrong abt my code...
at atin_sehgal@hotmail.com