Mateen Nasir

Ranch Hand
+ Follow
since Aug 01, 2001
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 Mateen Nasir

humm .. advice
firstly i gueess the most important thing is how u keeo your
mind cool and composed
exam is not tough
and i believe before u sit for the exam if u have done some good
mocks sinceeely u have a very good idea of not just abt pasing but also where u will score
marcus greens mocks are the closest to original
Jtips is too tough
but good if u want to score high
really opens up your mind
moughal books : good
vulmurugan study notes are really marvellous
my advice is : if u havent seen them yet please do : infact reading them will give u an idea of your preapaation
print them if u can ...

i am really thankful to this guy..
abt books mugahl's was what i read from
and a rule my friend said : if u can clearly understand whatu ra reading there is no way u can fail
and the most important : ranch i a marvellous place
believe me infact it fondled me so much that when i had i problem instead of opening up the book i would prefer to go to ranch and discuss it
i have taken other certification exams before where there was no corresponding forum like ranch and trust me : U WONT KNOW THE HELP IT GIVES IF U HAVE NOT FACED IT
Best of luck everyone
Bye
[This message has been edited by Mateen Nasir (edited October 10, 2001).]
20 years ago
passed today with 91 %
remember one thing -- ranch is the best guide to certification
just followed the advice of many who had done it before
Thanks to Almighty Allah
20 years ago
firstly thanks for the great explinations
now !!
we all know that varibales are accessed by reference type and not object type
so if i change this to
Process p = new Processor() ;
now when it runs then inside the child method this.b should
refer to the parent's variable because that is the process
reference type. but it still gets the same error
i hope u get it
what rules apply to the == operator for compile-error
the conversion rules or the casting rules
i.e. if a = ( type) b is correct
and a = b gives error
will a == b give compile error ?
a ques from jtips
class Process {
byte b=127;
Process() {
this.methodA();
}
void methodA() {
System.out.println("Value of b is = " + b );
}
public static void main(String [] args) {
Processor p = new Processor();
}
}
class Processor extends Process {
byte b=126;
Processor() {
System.out.println("Value of b = " + b);
}
void methodA() {
System.out.println("Value of b = " + this.b);
}
}
What is the Output?
1.Prints Value of b = 0 and Value of b is = 126.
2.Compile-time error occurs.
3.Prints Value of b = 126 and Value of b = 126.
4.Prints Value of b = 127 and Value of b = 126.

the answer gives is 1
i have run this and its the correct answer
but why/?
why is it not 4
first the parent cons is called and the value is 127
then child where value is 126
why a 0 printed
i cant get it !!
can we have a synchronized intance block or static block
i mean a syn block outside a method
how ?
i have tried and it gives an error
well well firstly warning is not an error : i guess guess a recommendation because u will still get a class file which will run perfectly fine
just as u said i tried the two below and the output
wow !
first the parent file Parent.java
package p;
import c.*;
public class Parent{
public static void main(String [] arg){
System.out.println( " Allah help me" );
Child ch = new Child () ;
Parent pa = ch ;
pa.zzz() ;
ch.zzz() ; }
final void zzz() {
System.out.println( " from parent" );
}
}
now the child file Child.java
package c;
import p.*;
public class Child extends p.Parent{
public void zzz ( ) {
System.out.println( " from child" );
}
public static void main(String [] arg){
System.out.println( " Allah help me" );
}
}

now the output
Allah help me
from parent
from child
I HOPE U GOT WHAT HAPPEEND
let me just hint
when u compile the child
yes the compiler found that u might be trying to override a
final method which since not being visible in the child class is
perfectly ok. so it did not give u any error. but warned that
if u had desired overriding that has not ocured
now when the compiler is compiling the parent it simply gives no warining why? that is because it finds that the parent has a method zzz and a child has a method zzz so the compile time check is ok
NOTE : move the main to the child and it does not compile
The real stuff comes at runtime
when we cast the child ch to parent reference and call zzz
method the parent sees that this is a final method of the refence and hence cannot be overridden ans therefore runs it there: I AM NOT SURE BUT MAYBE FINAL METHODS WORK LIKE STAIC
ONES IN THIS CASE BECAUSE U DO NOT NEED TO SEE THE RUNTIME OBJECT
so now while the child refernve runs the child method
the parent reference runs its method
although they both point to the same object( aliases) !!!
I hope i am making it clear
but its stil open for discussion
LASTLY before i leave the difference is unclear still : from this prog what i see i that anything visible and accesible and vice versa

[This message has been edited by Mateen Nasir (edited October 03, 2001).]

Originally posted by Valentin Crettaz:
If you put main in the Parent class you still have to import c.Child
Then when you try to compile the compiler still complains about method a (in class child) being not correctly overridden which makes sense since Child is a subclass of Parent. method a in Parent is still visible in Child but not accessible !!!
The cast you are trying to do in Parent won't help since the runtime type of p won't change because you are casting it...
HIH



what is the difference of being accessible and visible.
are't they the same
remember that a method that has default visiblity acts as a
private if seen from outside the package
and i dont guess child class should have any problems in overiding aa private method
Secondly , the presence of main in the parent's package should
allow the call to child method to compile ; that was what i meant
humm ...so waht do u think

Originally posted by Valentin Crettaz:
Mateen,
Concerning your moving the main into the Parent class:
you can move the main method in the Parent class but then you have to :
- import the Child class inside the Parent class
- declare your method "a" to be at least protected so that overriding works
When you run the Parent class the method "a" of the Child class gets called as expected...
HIH


once i move the main to parent class i guess the need to declare
protected is gone ( if i am not aiming at polymorphism of course)
see since the main method is in the same package as parent
( ofcourse since the same class ) paerent's method with default
access are visible to it
now what i guess will happen is : the child class will define a
method which will not be an overided method but a new method
now when i cast the child object to a parent reference and call
the parent method the compiler can see that the parent has this
method and will not give an error!
and when the program is run the child's method will b run
AgreeD ??
waiting for a comment !
what is the difference b/w inaccessible and invisible ?
( is it true for private too i.e. being invisible and inaccessible)
secondly consider what will happen if i move this main method to parent class and import the package c containing the child class there
will the polymorphism work then !!
waiting for comments !
final and default is the whole point in question.
the cause of all the debate
that since the method of parent is not visible in child the child method should not override. infact it should come as a new method in child not a overridden one .
I am not being able to try this because problem is i have tried this on differnt tools and dos window and results are different.may be a fault of my settings. so i want to discuss this on merit.
waiting !
take this
// Parent.java
package p;
public class Parent { final void a() {} }
// Child.java
package c;
import p.*;
public class Child extends Parent {
void a() {}
public static void main ( String [] args ) {
Parent p = new Child() ;
p.a() ; // which method parent or child
}
i.e. class parent in package p has a method a with package accessiblity and this method is not accessible in packge c
now what will happen in the main method
will polymophism work : will it give a compile errror
what will happen if i put the main method in class Parent and run it here as a inherited method
what will happen if i put the main method in parent and run parent.class after importing package c there
i hope u get my point
waiting for a good discussion here
hi
I found today that i can take paper from oracle platform too besides sun and earn the same certification. I know i might beable to save some bucks if i take the if from the oracle platform.
Tell me is the pattern different?
How different are the 2 things ?
i have prepared from Khalid's book specifically and
done test by marcus that i guess all aim at sun's exam .
can anyone please guide me.
i done want that in order too save a few bucks i do bad in the exam, although i dont mind falling back by a few percentage points.
will i get an SCJP certificate from oracle too!
Please guide me
Thanks in advance.
can anyone give me the link for
Velmurugan Periasamy's Notes
Thanks