Menu
Topics Index
...
`

Java book2610


If you need explanation Read this topic

If you need Answer Take test on this topic

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

A. Book name java
Pages 300
Price 275.0
B. Book name java
Pages 300
Price 275.5
C. Book name java
Pages 300
Price 275.50D
D. Compilation Error
E. Runtime Error
Topic: Scope Of Variables In Nested/Multiple Blocks

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.

D compilation error since price is local variable cannot access outside the scope

Posted by Vicky Maduri    2014-08-14 03:53:14


d.compilation aror..variable price is initialsd within a blok hence its scope is limitd withn it only...here price  val is chngd to 275 outsd the blok whrre it is declrd.henc it wil thro eror dat varibl price is not initialsd....

Posted by Asma Mujtaba Khan    2014-08-14 03:54:39


D.price is loca variable to the block,it cannot be used outside of the block since its scope is with in block

Posted by Prabhakar Reddy    2014-08-14 05:48:55


d

Posted by Zeg Abder    2014-08-14 07:36:13


Congratulations Vicky Maduri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-15 06:05:59


© meritcampus 2019

All Rights Reserved.

Open In App