Originally posted by may leung:
class Base {
int i;
Base(){
add(1);
}
void add (int v){
i+=v;
}
void print(){
System.out.println (i);
}
}
class Extension extends Base{
Extension(){
add(2);
}
void add(int v){
i += v*2;
}
}
public class Test {
public static void main (String args []) {
bogo(new Extension());
}
static void bogo(Base b){
b.add(8);
b.print();
}
}
a. 9
b. 18
c. 20
d.21
e.22
the ans is 22 but I am quite confuse in this question, can anyone explain in detail?
Thanks~
Originally posted by amit sanghai:
Hi everybody,
How can I call an Applet from another Applet?
Originally posted by balu gates:
Hi
Explain this..........
class Infinite {
public static void main(String args[]) {
double d1=1.0;
double d2=0.0;
int b=1;
d1=d1/d2;
b=(byte)d1;
System.out.println(b);
}
}
The answer is -1.
Explain.
Originally posted by Raukutam Sandeep:
hi everybody,
1) int a=10;
int b=0;
int c=a/b;
System.out.println(c);
2) double a=10.0f;
int b=0;
double c=a/b;
System.out.println(c);
The first program is giving an exception, however.
But the output of the second program is , i'm getting
'Infinity' on the console.
How is it happening?
Pls explain me.
regds,
Sandeep.
Originally posted by Stephen Peterson:
Exactly Sivaram! So is there a way to satisfy this requirement of the compiler?
Some dead-ends I went down. I setup an interface java file
BooleanResult.java
==================
import java.util.*;
interface BooleanResult { static boolean getResult(Vector v); }
But this did not work since the compiler tells me I cannot use
statics in an interface.
So I decided to try instantiating an object rather then just loading it and using it. I did the following:
(1) I took "static" out of my BooleanResult interface,
(2) I took "static" out of my TestClass2.java file, and added
"implements BooleanResult" to it
(3) I changed 2 lines in TestClass.java as follows:
BooleanResult o = new Class.forName(args[0]);
HasVector hasVector = new HasVector();
Now I cannot compile the TestClass.java because the Class.forName only works as a static:
$ javac TestClass.java
TestClass.java:17: Class java.lang.Class. forName not found in type declaration.
BooleanResult o = new Class.forName(args[0]);
^
1 error
$
By the way, I got that idea of trying an interface to solve this issue after looking at a very informative post by Peter Tran (his "personal example") posted to Object "Savvy" forum only a few minutes ago.