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 10: What will be the output when you run below program?

Question 10: What will be the output when you run below program?

class Welcome {

int counter1;

void Welcome() {

counter1 = 10;

}

void printValue () {

System.out.println("Counter Value = " + counter1);

}

public static void main(String[] args) {

Welcome wel = new Welcome();

wel.printValue();

}

} 

1. It will be having a compile time error. Because counter1 is not properly initialized.

2. It will compile and will print "Counter Value = 0"

3. It will compile and will print "Counter Value = 10"

4. It will give runtime error as it will not get value initialized for counter. And Null primitive is not correct.

Correct Answer : 2 Exp : In this code we will have default constructor. As void printValue() is not a valid constructor but a valid method. As constructor will never have a return type. And as we know, primitive int by default will be initialized with 0.

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 10: What will be the output when you run below program?