IndiaBIX
IndiaBIX
Start typing & press "Enter" or "ESC" to close
  • Home
  • Jobs
  • Results
  • Current Affairs
  • GK
  • Online Test
  • HR Interview
  • BLOG

What will be the output of the program? public class Test { public static void main(String args) { int x = 0; assert (x > 0) ? "assertion failed" : "assertion passed" ; System.out.println("finished"); } }

  • Home
  • Computer Science & Engineering
  • Java Programming Questions and Answers
  • Assertions - Finding the output
  • Discuss - 1415
1. 

What will be the output of the program?

public class Test
{
public static void main(String[] args)
{
int x = 0;
assert (x > 0) ? "assertion failed" : "assertion passed" ;
System.out.println("finished");
}
}

[A]. finished
[B]. Compiliation fails.
[C]. An AssertionError is thrown and finished is output.
[D]. An AssertionError is thrown with the message "assertion failed."

Answer: Option B

Explanation:

Compilation Fails. You can't use the Assert statement in a similar way to the ternary operator. Don't confuse.

Workspace Report
Leave a Comment

Computer Science & Engineering :: Java Programming Questions and Answers : More Exercises

  • Language Fundamentals - General Questions
  • Operators and Assignments - Finding the output
  • Exceptions - Finding the output
  • Inner Classes - General Questions
  • Height and Distance - Garbage Collections
  • Java.lang Class - General Questions
  • Declarations and Access Control - General Questions
  • Flow Control - General Questions
  • Objects and Collections - General Questions
  • Threads - General Questions
  • Assertions - Finding the output

Questions & Answers

Aptitude Chemical Engineering Civil Engineering Computer Science & Engineering Current Affairs Data Interpretation Electrical & Electronics Engineering Electronics & Communication Engineering General Knowledge Logical Reasoning Mechanical Engineering Non Verbal Reasoning Verbal Ability Verbal Reasoning

Interviews

HR Interview

Jobs

Sarkari Jobs

Results

Rojgar ResultSarkari Result

Admission

Admission 2023

Admit Card

Admit Card 2023

Answer Key

Answer Key 2023
copyright
Privacy Policy
© 2025 IndiaBIX. All Rights Reserved.

Report