rajesh dalvi

Greenhorn
+ Follow
since Oct 24, 2000
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 rajesh dalvi

answer to Q3 is 1. i.e. code will fail to compile.
As class B has no default no argument constru, but has one string arg Construct. So compiler won't create any defult constru for Class B.
So call to super in Class C is illegal.
So code will fail to compile.

Originally posted by vasu matt:
hello everybody
can anyone of u please explain me the answers for these questions.I am actually very confused.
code:
1)
Which statements concerning the effect of the statement gfx.drawRect(5, 5, 10, 10) are true, given that gfx is a reference to a valid Graphics object?
1)the rectangle drawn will have a total width of 5 pixels
2)the rectangle drawn will have a total width of 6 pixels
3)the rectangle drawn will have a total width of 10 pixels
4)the rectangle drawn will have a total width of 11
2))public class Qcb90 {
int a;
int b;
public void f() {
a = 0;
b = 0;
int[] c = { 0 };
g(b, c);
System.out.println(a + " " + b + " " + c[0] + " ");
}
public void g(int b, int[] c) {
a = 1;
b = 1;
c[0] = 1;
}
public static void main(String args[]) {
Qcb90 obj = new Qcb90();
obj.f();
}
}
1)000
2)001
3)010
4)100
5)101
ans:101pixels
3)Which statements concerning the following code are true?
class A {
public A() {}
public A(int i) { this(); }
}
class B extends A {
public boolean B(String msg) { return false; }
}
class C extends B {
private C() { super(); }
public C(String msg) { this(); }
public C(int i) {}
}
1)the code will fail to compile
2)the contructor in A that takes ine as arg will never be called as a result of constructing an object of class B or C
3)class c has three constr
4)objects of class B cannot be constructed
5)at most one of the constructor of each class is called as result of constructing an object of class c
regards
vasu


This is happening because you have done :

Actualy first return value is getting calculated and then the finaly block is executed. So the value retured by methodA is "BE"
only. Which is then again assigned to output.
So next print satatement in main print only "BE".
If you change your code to call

methodA() ;


only, without doing any assignment. then you will get o/p as "BEC". So now you will be convinced that finaly is called

Originally posted by Sudha Kris:
Some slight error in the code.
please change & try
public class test{
static String output ="";
public static void main(String args[]){

output = methodA();
System.out.println(output);
//It Prints just BE not BCE why??
}
public static String methodA(){
try{
Error();
return output+="A";
}
catch(Exception e){
output+="B";
return output+="E";
}
finally{
output+="C";
}
}
public static void methodE()throws Exception{
throw Exception
}

}
If I put a print at finally it prints output as BC.But when it returns to main that C isn't there. It just prints BE.
Can anybody explain this. Is it something to do with String being immutable?But then we are reassigning it to the same. So it should print the conactenated one.
Thanks
Sudha


Java Bean is always a Java Class. Only thing is that it should follow certan rules to be a Java Bean.
i.e. Java Bean is a sub-set of Java Class.

Originally posted by Sheldon Rego:
How do U basically distinguish between a Java class and a Java Bean on a technical level as there are a lot of debatable points if some could please elaborate on this topic


22 years ago
answer lies in order of evaluation of expression.
1. it will always evaluate expression from left to right.
2. also while evluating oprand if operand is applied a post unary oprator then first oprand is calculated and then immediately after that unary opration is performed.
3. finaly the assignment takes place.
so for
i=i++
it goes this way
1. i=0
2. immediately it performs i++
3 then assignment so i again becomes 0.
so now tell me what is the value of i for this
int i = 0
i = ++i + i++

well it is 2.

Originally posted by Sam:
Consider the following code :
class ABC
{
public static void main(String gh[])
{
int i=0
i=i++
System.out.println(i);
}
}
Guess the output !!!
Its 0 even after incrementing befre printing. Why guys, I wanna
know !!!
Help out.
regards,

[This message has been edited by Sam (edited November 06, 2000).]


22 years ago
This is the same example explained in RHE chapter 2.
The game is all about order of evaluatig expression and operator precedence and associativity.
In this example value will be stored in a[1] and that to 0.
final expression will become a[1] = 0;
How ?
Beacause in java all expressions are evaluated first from left to right.
so after this we will have
a -> a[1]
b -> b (just a reference)
0 -> 0 (literal)
so now expression becomes
a[1] = b = 0;
now associativity of oprators comes in to play.
= operator is evaluated right to left
so expression reduces to
a[1] = b (where now b = 0)
so finaly 0 is assigned to a[1]

Originally posted by sudha:
[B]Hi
This is from deepak's mock
Consider the following code :

1. int [ ] a = new int[ 2 ];
2. int b = 1;
3. a[b] = b = 0;

Value will be stored in what element of array a.
A.a[1]
B.none
C.a[0]
Answer given was a[1]
How can it be a[1].I didn't get this.Can any of you please explain.
Regards
Sudha


It gives ArrayIndexOutOfBoundsException for the last element.
This is because first condition is checked and then immdiately it increaments i.
so for last element value of i is actualy args.length.
here is some alternate working code:-

public class strprint {
public static void main (String[] args) {
StringBuffer str1 = new StringBuffer(50) ;
for(int i=0; i < args.length; ) {
str1 = str1.append(args[i++]);
str1 = str1.append(" "); }
System.out.println(str1);
}
}
value of i should be incremented after use in args[i]

[This message has been edited by rajesh dalvi (edited November 01, 2000).]
put your paragraph in < pre > data from database < /pre > tags.
This will prevent browser from formatting data and showit as it is.
But this will not apply PAGE fonts to this data.
To use your fonts use style sheet classes.

[This message has been edited by rajesh dalvi (edited October 24, 2000).]
22 years ago