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?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / surendrababu koppula
clone() method must be called on only cloneable objects so sub class must implement Cloneable marker interface
| Is This Answer Correct ? | 3 Yes | 0 No |
What is a finally block?
I declared main() method as private. But it still running and displaying the output. Please Answer it . Code Snippet as Below: import java.io.*; class over { private static void main(String[] args) { int high = Integer.MAX_VALUE; int overflow = high + 1; int low = Integer.MIN_VALUE; int underflow = low - 1; System.out.println(high + "\n" +overflow +"\n"+ low +"\n"+underflow); //System.out.println(overflow); //System.out.println(low); //System.out.println(underflow); } }
what is the use of abstract class and interface with example?
2 Answers Cycore, DNS, Technoram,
What do you understand by looping in java? Explain the different types of loops.
Why does java have two ways to create child threads?
What are the different types of collections in java?
What is the best way to findout the time/memory consuming process?
What is the difference between this() and super()?
What is the difference between JVM and JRE?
What is a package?
Can we have try block without catch block?
What does g mean in regex?