Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array extends/impliments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array extends/impliments" Watch "array extends/impliments" New topic
Author

array extends/impliments

pelluru rao
Greenhorn

Joined: Aug 03, 2000
Posts: 5
hello friends!
please answer the following question with reason
it is actually from Jargan.com
test3.html
6) Which of the following valid statements
Select all valid answers.
a) an array extends Object
b) an array extends Cloneable
c) an array implements Cloneable
d) an array extends primitive types like int, char, byte
e) None

waiting for reply
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1836
a) an array extends Object
//correct as the JLS says in 4.3.1
An object is a class instance or an array.
b) an array extends Cloneable
an array implements Cloneable and Serializable and does not extend them. remember Cloneable is an interface
c) an array implements Cloneable
// correct see above
d) an array extends primitive types like int, char, byte
// wrong one cannot extend primitive types only Objects
e) None
example program for an array that implements Cloneable

if an array did not implement Cloneable then a CloneNotSupportedException would be raized as in the following program

Regds.
Rahul

[This message has been edited by Rahul Mahindrakar (edited August 03, 2000).]
pelluru rao
Greenhorn

Joined: Aug 03, 2000
Posts: 5
TankQ Rahul.It is fine and enough.
pelluru rao
Greenhorn

Joined: Aug 03, 2000
Posts: 5
hello Rahul, the code in demo class require
some correction.
x.Clone returns an Object.So it should be
explicitly casted in avoid compile time error.
as
class demo
{
public static void main(String[] args)
{demo x=new demo();
try{
demo y=(demo) x.clone();
}
catch(Exception e){
System.out.println("Exception is " +e);
}
}
}
I think the reason for casting is correct.
If not correct me.
ThankQ
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1836
hi pelluru rao,
Guess you really worked on my code. good work. You are right clone() does return an Object which needs to be cast. I have made the necessary corrections.
By the way one can use [ CODE] and [ /CODE] between code blocks to make things look good. Just remove the space between [ C and [ /
Regds.
Rahul

[This message has been edited by Rahul Mahindrakar (edited August 03, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array extends/impliments
 
Similar Threads
Array Questions
enhanced for loop question
True Or False...
Casting
Exam Questions -Req. Clarification