midrisi

Greenhorn
+ Follow
since Oct 22, 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 midrisi

hi zhang,

I can't express in word....just saying Greaaaaaaaaaaaaaaaat than China Wall.
can u pl send me a notes to my e-mail: midrisi2@forindia.com
thanks alot and congrats,
Mohd Sharif Idrisi

[This message has been edited by midrisi (edited October 28, 2000).]
23 years ago
Hi Chetan,
First of all I would like to appreciate your efforts ....but when I went to your site I will not able to browse it out properly.It is showing some error.......Please correct it so that we will be get benefitted...

Thanks alot in advance.

[This message has been edited by midrisi (edited October 28, 2000).]
Hello Supriya,
As you have seen that B is being inherited thru A class and thru B main() method there is creation of B's class reference using new B().
This will invoke B() default custructor method as usual and after entering B() function it will call A() default constructor because as rule in java that parent class constructor should be intialised first then inherited class..so in this case compiler insert one statement called super(); just before System.out.println("BBB");
because u r not calling it explicitly...so it will implicitly insert it.
Hence due to it control goes to A class default constructor display a string "AAA" and after doSomething() of class A will be complied but remember in this case it is already overridden but u have a invoked it thru a object which is an instance of B class so "this" point to doSomething of B class only not A class method.
Hope u will get the point.May be the language would be confusing...sorry fot it.
If I would be get wrong pl correct me.
Thanks alot,
Sharif
code:


[This message has been edited by midrisi (edited October 27, 2000).]
can any one tell me what a typein questions???

Is it a type sort of free response??
give one example please?
It will print the value only 2
When you run the code it Sub().g() will be called as the inheritance suggest.But the g() will not having any access to f() function of Sub() as it is a function of parent class.So it will call f() function of Tester class itself.

I think your doubt has been cleared.
thanks

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

[This message has been edited by midrisi (edited October 22, 2000).]

1. public class T{
2. public static void main(String []agrs){
3. char c = 'c';
4. int i;
5. i = ++c;
6. System.out.println(c);
7. System.out.println(i);
8. }
9. }


As in the above code snippet you have intialised char c with 'c' and in the line 5, you are pre incrementing the c.In this case the java interpreter first type cast c variable to int type implicitly whose value is 99.And then inceremented it i.e. 99 + 1 =100 and assign to i variable in line 5.
In the line 6 you are printing the value of c which will become d whose value is 100. As java allow incremementing and decrementing oprations on string literals.
I think your query has been solved.



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

Originally posted by suneeta prattipati:
can anyone please explain what happens when the foll code is run
class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest
{ public static void main( String[] args )
{ Tree tree = new Pine();//i can't understand what this line is doing
if( tree instanceof Pine )
System.out.println( "Pine" );
if( tree instanceof Tree )
System.out.println( "Tree" );
if( tree instanceof Oak )
System.out.println( "Oak" );
else System.out.println( "Oops" );
}
}
Select all choices that will be printed:
a) Pine
b) Tree
c) Forest
d) Oops
e) (nothing printed)


As others fellow already told you that the ans will be a),b),d).
In the following statement
Tree tree = new Pine();
there is concept called object conversion rules has been applied
as it states that an reference of subclass can be converted to refernce of parent from which it has been inherited.Only upward move is allowed i.e. A parent reference cannot converted or type cast to sublcass reference.For more info refer to Robert And Heller book (topic is PRIMITIVE AND OBJECT REFERENCE)
I think this may solve your query.
Smile
Sharif

[This message has been edited by midrisi (edited October 22, 2000).]