Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

What will happen when you compile and run the following code?

  1. public class BooleanDemo {
  2.     public static void main(String args[]){
  3.         Boolean bObj = new Boolean("Hello World!");
  4.         System.out.println(bObj);
  5.     }
  6. }
a. Program will not compile
b. Program will throw runtime error
c. Program will print false
d. Program will print true

Answer:
C is the correct choice. Boolean wrapper class has a constructor which accepts string argument. So, there will not be any compilation error. If the string argument is equal to "true" regardless of its case, Boolean object representing value true is created. Otherwise it will be created as false. Hence, C is the correct choice.
Your rating: None Average: 3.5 (2 votes)
Share this

Post new comment