• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array extends/impliments

 
pelluru rao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1868
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TankQ Rahul.It is fine and enough.
 
pelluru rao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1868
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic