Santosh Bapat

Greenhorn
+ Follow
since Mar 13, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Santosh Bapat

OK, The book I have implies that they are interchangeable. Thanks for the help.
I wrote the following code for practice. The problem is when I substitute "Frame" for "Panel" nothing is displayed. I know that Panel doesn't extend Window so I also comment out the WindowListener, but I can't figure out why I can't create this as a Panel. As always, any guidance would be greatly appreciated.
import java.awt.*;
import java.awt.event.*;
public class license extends Frame{
public static void main(String [] args)
{
Frame p=new Frame();
p.setSize(500,200);
p.setLayout(new BorderLayout());
WindowListener wl=new WindowAdapter(){
public void WindowClosing(WindowEvent e){System.exit(0);}
};
p.addWindowListener(wl);
Button OK=new Button("OK");
TextArea t=new TextArea("By clicking OK, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah\n, blah, blah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah,",5,250);
p.add(BorderLayout.CENTER,t);
p.add(BorderLayout.SOUTH,OK);
p.validate();
p.setVisible(true);
}
}
Thanks that does help. Just to further qualify my own thinking, is the following statement accurate:
I can't say:
Vegetable v=new Food();
but I can say:
Vegetable v=new GreenPeas();
First of all be wary of this book. There are a lot of blatent errors with the sample questions (but the chapters themselves cover the material quite thoroughly and concisely)
Anyway:
class Food implements Eatable{}
class Vegetable extends Food{}
class GreenPeas extends Vegetable{}
class Meat extends Food{}
....
public Vegetable getSomething(){
return XXXXXXXXXXXXX
}

What can legally replace XXXXXXXXXX
a) new Vegetable();
b) new Food();
c) new Meat();
d) new GreenPeas();
I say a and b, book says a and d because GreenPeas is a type of Vegetable but Food is not a type of Vegetable. It seems that Food is "narrower" than Vegetable so you should be able to return it, but GreenPeas is "wider" than Vegetable so you shouldn't be able to return it when the return type is a Vegetable Object.
My thinking here is that you can return a short when the return type is int but you can't return a long when the return type is int. Any clarification would be most appreciated.
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
The object which string1 originally pointed to is eligible for garbage collection after these four lines?
Thanks Dave. That makes sense.
Hi all. This is my first post although I have been sucking information from this site for quite a while now. Can anyone tell me why the following program prints the numbers 0-9 in a random order regardless of whether or not the run() method is synchronized. As (I thought) I understood it, synchronized will only give one Thread object access to the method at a time. I would think that if I used "synchronized" the numbers 0-9 would be printed out in order 4 times. Thanks in advance for your help

public class tosh extends Thread
{
static Thread t1=new tosh();
static Thread t2=new tosh();
static Thread t3=new tosh();
static Thread t4=new tosh();
public static void main(String [] args)
{

t1.start();
t2.start();
t3.start();
t4.start();
}
public synchronized void run()
{
for (i=0;i<10;i++)
{
System.out.println(i);}
}
}