www.HadoopExam.com

HadoopExam Learning Resources

Following are the Oracle Java and Oracle SQL Products Provided by HadoopExam Learning Resources
Free Core Java 1Z0-808 Training Java 1Z0-808 Questions and Answers Java 1Z0-809 Questions and Answers Questions for Oracle 1Z0-060 : Upgrade to Oracle Database 12c Administrator Oracle Database 12c: SQL Fundamentals

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

You have no rights to post comments

You are here: Home Oracle Java 1Z0-809 Question 11: You have been given below code, what is the expected behavior?