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 are the procedures?
How do you sing an Applet ?
What is mean by exception?
What do you understand by final value?
What is java in detail?
how to create multithreaded program? : Java thread
Can bool be null?
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?
What is the generic function?
What is the byte order of byte buffer?
Which sorting is best in java?
Which method returns the length of a string?
Which package is always imported by default?
Explain about features of local inner class?
How to provide security in java