• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mala Gupta's Twist in the Tale 1.2 OCAJP Reviewer  RSS feed

 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Accdg to the Twist in the Tale:

Question: Examine the content of the following Java source code file, Multiple2.java,
and select the correct option.

// contents of Multiple2.java
interface Printable {
//.. we are not detailing this part
}
class MyClass {
//.. we are not detailing this part
}
interface Movable {
//.. we are not detailing this part
}
public class Car {
//.. we are not detailing this part
}
public interface Multiple2 {}
Options:

a The code fails to compile.
b The code compiles successfully.
c Removing the definition of class Car will compile the code.
d Changing class Car to a non-public class will compile the code.
e Changing class Multiple2 to a non-public class will compile the code.


. The answers are a,c,d. But why is d included? I tried making the class 'Car' private or protected and it resulted in compilation error though they are now non public class.
I think that it should mean to be not including access modifiers?


 
Stuie Clarky
Ranch Hand
Posts: 98
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Default access (no modifier) is a non-public option, in the same way that private and protected are. Did you try running it with default access?

S
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Liek wrote:I think that it should mean to be not including access modifiers?

Simply put: A java file called Multiple2.java is allowed only ONE public class, and it MUST be called Multiple2.

Also: I'm pretty sure that private is not allowed as a qualifier on a top-level class. A nested class (ie, a class defined inside another) can be private, but not otherwise.

HIH

Winston
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!