Every class extends object but why it is not possible for
every object to invoke clone() method. ideally protected
methods should be accessible from sub classes. isn't it?
Answer Posted / aslam
Since the method is protected we can access clone method
only within the package or from subclasses outside the
package.
for ex:
class A{
public static void main(String arg[]){
new A().clone();
/* This is legal since class A is a subclass of Object and
we r accessing within the subclass*/
}
}
class B{
public static void main(String arg[]){
new A().clone();
/* Illegal since we r accessing it from outside object */
}
}
| Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
What kind of variables can a class consist?
Explain the Propertie sof class?
enlist some features of jdk.
Define max and min heap, also the search time of heap.
How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?
What is the difference in between cpp and java? Can u explain in detail?
Can a static method be final?
What are actual parameters?
How many boolean functions are there?
What is complexity and its types?
What is the difference between size and length in java?
Explain the scope of a variable.
What's the difference between int and integer in java?
What is a instance variable in java?
Is it possible to specify multiple jndi names when deploying an ejb?