Declarations and Access Control Logic
© examsiri.com
Question : 17 of 29
Marks:
+1,
-0
Insert six modifiers into the code such that it meets all of these requirements:
1. It must be possible to create instances of Alpha and Beta from outside the packages in which they are defined.
2. When an object of type Alpha (or any potential subclass of Alpha) has been created, the instance variable alpha may never be changed.
3. The value of the instance variable alpha must always be "A" for objects of type Alpha.
Code:
Modifiers:
1. It must be possible to create instances of Alpha and Beta from outside the packages in which they are defined.
2. When an object of type Alpha (or any potential subclass of Alpha) has been created, the instance variable alpha may never be changed.
3. The value of the instance variable alpha must always be "A" for objects of type Alpha.
Code:
package alpha;
Place here class Alpha{
Place here String alpha;
Place here Alpha () { this("A");}
Place here Alpha (String a) { alpha = a;}
}
package beta;
Place here class Beta extends alpha.Alpha{
Place here Beta(String a) { super(a);}
} Modifiers:
Go to Question: