1,876 views
0 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 1 vote

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
Position:
Show:

Related questions

1 1 vote
1 answers 1 answer
2.5k
2.5k views
LavTheRawkstar asked Jun 28, 2016
2,501 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 0 votes
0 0 answers
384
384 views
LavTheRawkstar asked Jun 29, 2016
384 views
Which of the following is not a type of Garbage Collection Mechanism ?A) Reference countingB) Finalization queue C) Mark and sweep collectionD) Generational collectionI j...
0 0 votes
1 answers 1 answer
1.4k
1.4k views
LavTheRawkstar asked Jun 28, 2016
1,389 views
What is the difference between the following shift operators : A) >> operatorB) > operatorC) << operator
2 2 votes
1 1 answer
779
779 views
LavTheRawkstar asked Jun 28, 2016
779 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...