mohammed mustafa

Greenhorn
+ Follow
since Jan 11, 2001
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 mohammed mustafa

i am an engineer, with 1 year of experience in java, i am jcp also, interested in your offer(hyderabad, india),
please mail me at mustafa_mim@yahoo.com
23 years ago
in awt programs paint method is called explicitly, we can call it by repaint() but this also draws on the main container but how to invoke it to draw it on sub container like a panel
as we cannot directly instantiate Graphics object(since it is abstract) to pass it as an argument in paint method call.
oh that answer i think must be d, sorry that was a typing mistake as i also know that there is no such thing as network exception
is this a correct way to instantiate inner class in main method of outerclass
OuterClass.InnerClass inner = new OuterClass.new InnerClass();
i think it should be
Outerclass.InnerClass inner=new OuterClass().new InnerClass();
please corect me if i am wrong
mustafa
in one of javacaps sample test question
**********************
22. There are two computers are connected to internet, one computer is trying to open a socket connection to read the home page of another computer, what are the posible exceptions thrown while connection and reading InputStrem.
A) IOException
B) MalformedURLException
C) NetworkException
D) ConnectException
Answer is A,B
but i thing that c should also be correct since the remote host may also refuse connection
if i am wrong please explain why
regards
mustafa
hi Jane,
can you explain me this, if two separate calls to x1.toString()is creating two different objects but i have checked their hashcodes and to my surprise they are same; how can two different objects have same hashcode
please explain....
mustafa
hi, snehal
don't get confused ,you see it's so simple, when you are creating the object of AQuestion
the JVM will call the default constructor which will check for all the defined member variables
and assign them their default values, since you have not coded one for desired initialization
then the value of variable "i" is determined by calling giveMeJ() and at this time j is initialised to
0; the default for int hence you see i as 0 in output.
even if you have called for i value to be printed in the giveMeJ() method it would have printed its default
value which is also 'o'.
::
private int giveMeJ()
{ System.out.println(i);
return j;
}
HOPE THIS HELPS
MUSTAFA
------------------
hi Arun, if you again check, the second thread is starting when the count on first thread is around 150 or so, this is what i mean as the second thread is not starting after the first thread has printed "HELLO"
" HOW ARE" "YOU?"
this is what i am getting on WIN ME, jdk1.3
mustafa
i am in a strange problem the code below creates two threads which try to execute synchronized method prin in class M1 but the threads are executing it simultaneously not after one thread finishes, please explain this behaviour
class M2 implements Runnable{
public M2(){
Thread t=new Thread(this);
t.start();}
public void run(){
M1 k=new M1();
k.prin();}
}
class M3 implements Runnable{
public M3(){
Thread t=new Thread(this);
t.start();}
public void run(){
M1 k=new M1();
k.prin();}
}
public class M1{
synchronized void prin(){
for (int i=0;i<1000;i++)
{System.out.print(i+" "); }
System.out.println("HELLO");
System.out.println("HOW ARE");
System.out.println("YOU ?");
}
public static void main(String ag[]){
M2 m=new M2();
M3 mm=new M3();
}
}
can any one explain me the concept behind explicit casting ; in one of khalids mocks there was a question on casting
class A {}
class B extends A {}
class C extends A {}
public class Q3ae4 {
public static void main(String a[])
{
A x=new A();
B y=new B();
C z=new C();
// insert statement here
}
}
Choices :
(i) x=y;
(ii)z=x;
(iii) y=(B)x;
(iv) z=(C)y;
(v) y=(A)y;
I could not understand why can't we cast like the choice 'iii'
above since y is the reference to the sub class of A
after exception has occured the program code in try -catch are executed
after which it is mandatory to transfer control to finally and return
is not just a statement but it is control transfering statement and compiler
knows it better hence it is never executed in such cases . And after finally
the method which gave the exception is aborted and the program flow is continued.

------------------
in one of khalids example codes a superclass type reference assigned to a subclass reference
is calling the member variable line# 14
// Exceptions
class InvalidHoursException extends Exception {}
class NegativeHoursException extends InvalidHoursException {}
class ZeroHoursException extends InvalidHoursException {}
class Light {
protected String billType = "Small bill"; // (1)
protected double getBill(int noOfHours)
throws InvalidHoursException { // (2)
double smallAmount = 10.0,
smallBill = smallAmount * noOfHours;
System.out.println(billType + ": " + smallBill);
return smallBill;
}
}
class TubeLight extends Light {
public String billType = "Large bill"; // (3) Shadowing.
public double getBill(final int noOfHours)

throws ZeroHoursException { // (4) Overriding.
double largeAmount = 100.0,

largeBill = largeAmount * noOfHours;

System.out.println(billType + ": " + largeBill);

return largeBill;

}

public double getBill() { // (5)
System.out.println("No bill");

return 0.0;

}
}
public class Client {

public static void main(String args[])

throws InvalidHoursException { // (6)
TubeLight tubeLightRef = new TubeLight(); // (7)
Light lightRef1 = tubeLightRef; // (8)
Light lightRef2 = new Light(); // (9)
// Invoke overridden methods

tubeLightRef.getBill(5); // (10)
lightRef1.getBill(5); // (11)
lightRef2.getBill(5); // (12)
// Access shadowed variables

System.out.println(tubeLightRef.billType); // (13)

System.out.println(lightRef1.billType); // (14)

System.out.println(lightRef2.billType); // (15)
// Invoke overloaded method

tubeLightRef.getBill(); // (16)

}
}
since the subclass member overshadow the superclass members how does the
super class member variable protected String billtype="small bill"
is called
out put is large bill:500.0
large bill:500.0
small bill:50.0
large bill
small bill
small bill
no bill
please explain

------------------