This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

some doubts

 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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?
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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...")
reply
    Bookmark Topic Watch Topic
  • New Topic