File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes some doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "some doubts " Watch "some doubts " New topic
Author

some doubts

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
hi..
following are my doubts...just clear them... i have the answer but just wana confirmation regarding them

1. If class is default ( not public ) and if its package is imported will that class will be accessible to the program which import it ? and the protected member within it ?

i think class will not be imported to other classes if its not public and if class is not accessible the there is no question of accessing its public/protected member ... Right ??


2. IF superclass reference variable is assigned to subclass object will it be able to call super class protected overloaded/overridden method/member ?

I think, in case of overloaded method as per above case only overloaded method of superclass will be called because ..when overloading method reference type is taken into a/c and in overidding case the overriding method will be called as here object type is of subclass and only those method will be called which are overridden . is i am right ?


3. what if in overloading methods one method accept String argument and other accepts Integer object and if invoked the method will null parameter, which method will be invoked.. ?

i think the method with more specific argument will be invoked .. i think in this case String will be invoked as it more specific and inherited from class Object ?
is i am Right ?

4. while assinging to char primitive let say char a='\u15000' and char b=15000 // will same value will be stored in char primitive ?

5. if in the for loop if some statement is unreachable then why that program will not compile ? for eg. if u use continue with if statement and making code below the continue unreachable..then ..why don't it get compile..
what is the logic... ? unreachable statement should be get compile..

6. can we use throw statement within the catch block { } and if used where it will be caught...if there is next catch which can catch that thrown exception ..will that next catch block will catch the exception thrwon ...

7. i have not seen where its written that break statement can also be used to block only i.e( except loops) where continue statements can be use only in loop blocks .. where this is written in K&B ?
i face one question in khallid mughal..


Thanks and Regards, Amit Taneja
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
1. I think you have it right. The class will only be visible to Classes in the same package, so you can't access it through import

2. When you have a superclass reference, you can only access methods available to the superclass without a cast, so overridden methods are available but will call the method of the subclass (you can't call the super version of the method) and overridden methods are available whether declared in the super class or the subclass (provided they are accessable)

3. Why is String more specific than Integer? The hierarchy is:


I don't know the answer to this one either, but I am interested to know why you think String is more specific?

4. Won't compile - unicode chars are given with '\uxxxx' where x is a valid hex character, so even if you were to try char a = '\u1500' and char b = 1500, the answer would be no, because a would be 1500 hex, which is 5376.

5. can you give an example?

6. You can rethrow an exception when you catch it. It will be just like you didn't catch it in the first place, so your method must declare that you throw it.

7. I am having trouble understanding the question, but break statements can be used for example in switch blocks, so they are not restricted to loops.
[ June 04, 2005: Message edited by: Timmy Marks ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[amit]: 3. what if in overloading methods one method accept String argument and other accepts Integer object and if invoked the method will null parameter, which method will be invoked.. ?

Well, what happens if you compile and run an example such as you describe?


"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[amit]: 5. if in the for loop if some statement is unreachable then why that program will not compile ? for eg. if u use continue with if statement and making code below the continue unreachable..then ..why don't it get compile..
what is the logic... ? unreachable statement should be get compile..


The logic is that Java's creators believed that in most cases, if a programmer creates an unreachable statement, that means the programmer was confused and did not understand the code they wrote. Why would someone want to write code with an unreachable statement? Probably it's an error. So the compiler helps the confused programmer by pointing out the error and forcing them to correct it.

That doesn't mean that all programmer errors will be caught by the compiler. But in general, if a type of error is easy for the compiler to detect, there's a good chance the JLS has required the compiler to detect it and report it as an error. The rules for unreachable statements are here; note that there's a specific exception to the principles I've discussed here which is discussed at the end of that section. (Beginning with "The rationale for this differing treatment...")
 
wood burning stoves
 
subject: some doubts