wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam LAb Question on Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam LAb Question on Arrays" Watch "Exam LAb Question on Arrays" New topic
Author

Exam LAb Question on Arrays

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634





objects that can be put to A can only be of type C

why ??


[Thumbnail for Capture2.PNG]



OCPJP 6.0 93%
OCPJWCD 5.0 98%
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

no thats not true
objects that can be put to A can only be of type C


you can put objects of type A ,B or C

B extends A
C extend B
means C extends A


Thanks & Regards
Sumit Kothalikar
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

If I ask, can you refer a Super class object by a sub class reference?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

sumit kothalikar wrote:no thats not true
objects that can be put to A can only be of type C


you can put objects of type A ,B or C

B extends A
C extend B
means C extends A

You are wrong! Check the below code.
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

please see the explanation

i tried to put new A() into a[0]
compilation fails
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

mohitkumar gupta wrote:please see the explanation

i tried to put new A() into a[0]
compilation fails

Compilation fail? No. Check it again please.!
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

@mohit..

I donot think your line no 6 will compile because a has already been declared in above line it will give compile time error...Please check it......
and one more thing..

You can only refer superclass to sublcass..

Subclass referece cannot be refer to a superclass Object........These are the restriction put in java..


SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

mohitkumar gupta wrote:please see the explanation

i tried to put new A() into a[0]
compilation fails


It will compile because a[0] is the reference type of class A........
share the error which you get

May be you have done the mistake in typing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exam LAb Question on Arrays
 
Similar Threads
Question on Inheritance.
Abstract Class
how FileOutputStream and ObjectOutputStream working here
Does is-a imply has-a ?
CertPal Question