920 views
0 votes
0 votes
What is the output of the following code segment ?

Boolean b= false ;

if (b = true)

System.out.println("true");

else

System.out.println("false");

(A) true

(B) false

(C) compiler error

(D) none

i believe eithher the question or the answer given is wrong

what you all people say ??

1 Answer

Best answer
1 votes
1 votes

It will give output true

#include <stdio.h>
typedef int bool;
#define true 1
#define false 0
 
int main(void) {
	bool b= false ;
 
if(b = true) //here equal to is an assignment statement
 
printf("true"); // code come here and simply print true
 
else
 
printf("false");
 
	return 0;
}

import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Boolean b= false ;
 
if (b = true)
 
System.out.println("true");
 
else
 
System.out.println("false");
 
	}
}
edited by

Related questions

1 votes
1 votes
1 answer
1
LavTheRawkstar asked Jun 28, 2016
2,130 views
Which of the following methods from Object is final ( that it cannot be overriden ) ?(A) finalize method(B) clone method(C) hashCode method(D) getClass method
0 votes
0 votes
1 answer
3
LavTheRawkstar asked Jun 28, 2016
920 views
What is the difference between the following shift operators : A) >> operatorB) > operatorC) << operator
2 votes
2 votes
1 answer
4
LavTheRawkstar asked Jun 28, 2016
434 views
Why Java does not support multiple inheritance?i want answer in simple words. i have searched for this answer in every textbook.Everytext just says that it doesnot suppor...