Menu
Topics Index
...
`

Java book


If you need explanation Read this topic

If you need Answer Take test on this topic

Java book
What will be the output of the following program?
public class Book {
    public static void main(String[] args) {
        String book = "java";
        int pages;
        System.out.println("Book name " + book);
        double price = 275.50D;
        System.out.println("Pages " + pages);
        pages = 300;
        System.out.println("Price " + price);
    }
}

A. Book name java
Pages 300
Price 275.50D
B. Book name java
Pages 300
Price 275.5
C. Book name java
Pages 0
Price 275.5
D. Compilation Error
E. Runtime Error
Topic: Scope Of Variables In Same Block

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer : D CompilationError
At Line:7 we are trying to print a varaible which is not initalized

Posted by Deepak Kumar Yadav    2014-06-03 04:07:31


Answer D
Trying to print the integer variable "pages" without initializing it with a value returns an error.

Posted by Sreemukha Taduru    2014-06-03 04:48:27


Ans D
Printing the value of " pages " before it was initialized leads to compilation error.

Posted by Vijju Deva    2014-06-03 05:52:43


Ans : D First Print statement  will print Book name and then Second Print statement goes to compilation error because the "Scope" of the variable is only before the Print statement..

Posted by Damu Surya    2014-06-03 10:08:01


Congratulations Deepak Kumar Yadav. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-04 04:51:40


© meritcampus 2019

All Rights Reserved.

Open In App