HadoopExam Learning Resources

HadoopExam Training, Interview Questions, Certifications, Projects, POC and Hands On exercise access

    40000+ Learners upgraded/switched career    Testimonials

Question 14: package com.hadoopexam;

Question 14: package com.hadoopexam;

class Parent {}

class FirstChild extends Parent {}

class SecondChild extends Parent {}

class Welcome {

public static void main(String[] args) {

Parent[] array = new FirstChild[3]; //n1

array[0] = new FirstChild(); //n2

array[2] = new SecondChild(); //n3

System.out.println(array.length); //n4



1. It will throws an ArrayStoreException, when program is run. 

2. It will throw compile time exception at line n1 and n2 both. 

3. It will throw compile time exception at line n3. 

4. It will run successfully and print 3 

5. It will run successfully and print 2 

Correct Answer : 1 Exp : Creating an array with child class and assigning type of array with parent is fine. Hoiwever, we have created an array of FirstChild, which has parent child relation only with the Parent class. SecondChild has no relation with FirstChild. Hence, if you are try to add an SecondChild object to FirstChild it will throw Runtime exception named as ArrayStoreException.

I have cleared my Java 1Z0-808 Certification exam with 92% using this simulator

I have cleared my Java 1Z0-809 Certification exam with 96% using this simulator


Visit Home Page : http://hadoopexam.com for more detail . As you are not blacklisted user.

You are here: Home Oracle Java 1Z0-809 Question 14: package com.hadoopexam;