ashu s

Greenhorn
+ Follow
since Feb 12, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by ashu s

Which of the following methods can be legally inserted in place of the comment //Method Here ?
class Base{
public void amethod(int i) { }
}
public class Scope extends Base{
public static void main(String argv[]){
}
//Method Here
}
1) void amethod(int i) throws Exception {}
2) void amethod(long i)throws Exception {}
3) void amethod(long i){}
4) public void amethod(int i) throws Exception {}
answer is 2 and 3. I think it should be only 3 because in super class method is not throw any exception. if I'm wrong can you please correct me?
Thanks,
Ashu
Which of the following lines of code will compile without error
1)
int i=0;
if(i) {
System.out.println("Hello");
}
2)
boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println("So true");
}
3)
int i=1;
int j=2;
if(i==1| | j==2)
System.out.println("OK");
4)
int i=1;
int j=2;
if(i==1 &| j==2)
System.out.println("OK");
According to me answer is 2 and 4 but when I checked the answer it is 2 and 3. I think one can use short circuit operator only with boolean values. Am I right?
Thanks in advance
Ashu
Mike,
Thanks a lot.
You are damn right what I was thinking.
23 years ago
I'm woking on assignemnt which includes 5 concentric circles like target sign. One white circle one red and so on. If user click anyone of them i want to get those x , y points. and user should see small dot on that target sign. I wrote some code as follows. Right now I can see concentric circles but when I click on those circle I'm getting null pointer exception at runtime. Can somebody please explain me why?
Thanks in advance,
Ashu
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/*
<applet code = Target.class height = 400 width=400>
</applet>
*/
public class Target extends Applet implements MouseListener {
private Label statusBar;
int x,y;
public void init() {
Label statusBar = new Label();
}
public Target() {
Target t = new Target();
t.addMouseListener(this);
}


public void paint(Graphics g) {

g.setColor(Color.red);
g.fillOval(0, 0, 240, 240);
g.setColor(Color.white);
g.fillOval(20, 20, 200, 200);

g.setColor(Color.red);
g.fillOval(40, 40, 160, 160);
g.setColor(Color.white);
g.fillOval(60, 60, 120, 120);

g.setColor(Color.red);
g.fillOval(80, 80, 80, 80);
g.fillOval(x, y, 4, 4);
}
public void mouseClicked(MouseEvent e)
{
x = e.getX();
y = e.getY();
statusBar.setText(e.getX()+","+e.getY());


repaint();
}
public void mousePressed(MouseEvent e){ }
public void mouseEntered(MouseEvent e){ }
public void mouseExited(MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
}

23 years ago
4) Abstract method cannot be final. True or False ? Answer: True
5) Abstract method cannot be static. True or False ? Answer: True
6) Abstract class cannot have static methods. True or False ? Answer: False
7) Abstract class cannot have final methods. True or False ? Answer: False
8) A final class cannot have static methods. True or False ? Answer: False
9) A final class cannot have abstract methods. True or False ? Answer: True
I wrote my answers in front of question. Is it correct? It it's not please let me know.
Thanks in advance,
Ashu
23 years ago
Which of the following valid statements
Select all valid answers.
a) all classes extend Object by default
b) all classes implement Cloneable by default
c) In Java a class cannot extend more than one class.
d) In Java a class cannot extend a class and implement another interface at same time
e) In Java a class cannot implement a class.
According to me answer is a, c, e but when I checked the answer it is a, c, d but I think d is incorrect. Can somebody explain to me?
23 years ago
Thank you very much Nathan and Huiying.
23 years ago
Can java keywords consider as alegal identifier?
consider this e.g.
a. number
b. 12color
c. abstract
can somebody tell me where abstract is legal keyword or not?
23 years ago