Dheeraj Mhetre

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

Recent posts by Dheeraj Mhetre

Which of the following statements are true?
1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
Answer is 3 and 4
I think we can instantiate interfaces with the help of anonymous classes.
Please clear my doubt
hi Rohan ,
we cant instantiate interface at all,
because it has no constructor .....we can make reference of it.....
..... now what is ur doubt is about Anonymous class ....there
we make an instance of a class which ...imlements
that interface........so that insance is of that class not
of the interface.....
bye dheeraj
// A public constructor throwing an exception.
public ConstructorTest(int j) throws Exception {
i = j;
System.out.println("Value of parameter is: " + i);
}

// Another public constructor throwing an exception.
public ConstructorTest(String s) throws Exception {
st = s;
System.out.println("Value of parameter is: " + st);
}

public static void main(String args[]) {
try {
ConstructorTest c1 = new ConstructorTest(10);
ConstructorTest c2 = new ConstructorTest("Passed");
}
catch(Exception e) {}
}
}

Output from the program -
Value of parameter is: 10
Value of parameter is: Passed

hi friend , u have come to the right point ,
obviously constructors can throw exceptin at any time,
but now there is one problem with that, u have taken a simple example,...but if there is one super class , the sub class extending the super one,
now if i make an instance of a sub class ....the sub class constructor will call supers constructor implicitly,
so if the Super's constuctor throws an Exception ...it has to
catch in subclass constructor....so there must be try block in Sub's constructor....BUT....then try become before SUPER call statement...
which is not allowed ie SUPER must be first statement in Constructor .....so
FOR THIS problem there is no solution in JAVA....
got it.........bye
dheeraj.....

public class Base {
static String string = "A string of Base";
public static Base getBase() { // 1
Base b = null;
return b;
}
public static void main(String[] args) {
System.out.println(getBase().string); // 2
}
}
Output -
A string of Base
hi friend ,i think what happens here is, u have declared
the string variable as static in the class ....so it is acessible all the time in the class with class name , without class name, and also with object ref,.......so even if U made
the reference to null in the method ...u will get the answer
same ie u are getting ....
right....correct me if i am wrong ...bye....
dhiraj

hi thats right , i also in search of the same,
i have solved that test ....but the wrong answers
i could not check so please mail me the answers as early as posible...my mail ID is <[email protected]>
my exam is on 5 th......bye dhirya
If you want subclasses to access, but not to override a superclass member method, what keyword should precede the name of the superclass method?
hi Manfred.....
thank you for quick reply... now i got the answer...
that means " add " method of Extension class is called
thrice....
ok thank you...
dheeraj
24 years ago
hi all java Ranchers please Explain me how the code works...
it gives answer 22 ...

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 foo
{
public static void main(String args[])
{
logo(new Extension());
}
static void logo(Base b)
{
b.add(8);
b.print();
}
}
24 years ago

hi Pooja,
firstly congratulation for achieving a BIG BIG target,
there must be a lots of efforts by you behind it,
i am planning to appeare the test in next month ,upto end
( depends upon getting date)
so i will be very thankful to you if you give me some tips
regarding study and the attitude towords questions on newly pattern....
my mail ID [email protected] bye then....dhiraj
24 years ago
hi everybody,
i am here to prepare for the SCJP test, infact i am
preparing for that,
if anyone of you have know about the links of JAVA and
best links for sample tests which is on the basis of current
java tests please reply me on my mail ID
thanking you........bye to all for now
[email protected]
24 years ago