# www.HadoopExam.com

HadoopExam Learning Resources

40000+ Learners upgraded/switched career    Testimonials

## Question 11: You have been given below code, what is the expected behavior?

Question 11: You have been given below code, what is the expected behavior?

package com.hadoopexam;

class Welcome {

int distance;

Welcome(int x) {

this.distance = x;

}

public void increSpeed(int time) {

int timeTravel = time;

class Car {

int value = 0;

public void speed() {

value = distance / timeTravel;

System.out.println("Velocity with new speed " + value + "kmph");

}

}

new Car().speed();

}

public static void main(String[] args) {

Welcome wel = new Welcome (100);

wel.increSpeed(60);

}

}

1. It will give compile time error.

2. It will give run time error

3. It will print "Velocity with new speed 1kmph"

4. It will print "Velocity with new speed 1.4kmph"

5. It will give NullPointerException

Correct Answer : 3 Exp : It is a Question of mixing Inner classes as well access outer class variable. As we know distance variable is accessible from inner class.

While creating constructor of Welcome class , we assigned distance=100. In Inner class we are acceding defined value of timeTravel=60. Hence, value= 100/60 , as we know both are int value hence result would be int value. Which is 1. So it will print Velocity with new speed 1kmph

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.