• Post Reply Bookmark Topic Watch Topic
  • New Topic

Q's on my Exam Prep!  RSS feed

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a neophyte to Java, but seeking for better stature that's why I've decided to prepare for the SCJP 1.4 exam. Please help me with my questions. Thanks to you all in advance. God bless!
Q1. import book.*;
What does this wildcard import statement mean? That the compiler will search for all classes that will later be used and furthermore, includes the class files in my user-defined or default package so that there are no accessibility problems?
Q2.Can an abstract subclass extend from a concrete superclass?
Q3. short m1(){return (short) 42;}
Is the cast (short) required or optional?
Q4. If a subclass-in-the-same-package inherits a protected member, what happens to the member? Does the subclass also inherit it as 'protected'?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I believe that
1) Yep, wildcard statement in "import books.*" means that you will be able to use all classes from package books in your source file. Note that if you also have package named books.whateverbooks, it won't be included, that is, wildcard is not recurrsive.
2) I think yes.
3) I believe it is optional here... Try compiling it.
4) It also inherits it as protected as long as you tell the compiler to do so, that is, define the overidding method as protected as well. When you override a method, it's access modifier can stay the same, or be less restrictive. So, assuming method is called myMethod, in the subclass you can either have public myMethod(){} or protected myMethod(){}
Be warned that this is the 2nd day I am studying for SCJP...
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to follow up on Andris' answer to number 2, he is correct, you can create an abstract class by extending a concrete class.
Good luck!
 
K Ville
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thanks, my fellah greenhorns here. I still have a lot of questions, but I forgot to bring my list with me. Hope to hear more from you again. Thanks!
 
K Ville
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another question, please.
Q: interface MyInterface1{
void foo();
}
interface MyInterface2{
int foo();
}
Is it true that an implementer class is NOT allowed to implement these interfaces together because both have methods that have the same signature but different return types?
Follow-up: Why can an interface declare that it throws an exception in its throws clause, yet its implementer is not obligated to declare it? If the implementing class is not required to declare it, is it now obligated to handle it in a try/catch?
 
Look ma! I'm selling my stuff!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!