*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assert" Watch "assert" New topic
Author

assert

Hasitha Randika
Ranch Hand

Joined: Sep 04, 2007
Posts: 50
class A{
public static int y;
public static void foo(int x){
System.out.println("mike");
y = x;
}
public static int bar(int z){
System.out.println("bar");
return y = z;
}
public static void main(String ar[]){
int t =0;
assert (t>0): bar(7);
assert (t>1): foo(8); //can't we add a assert statement to a void method
System.out.println("gayani");
}
}

can't we add a assert statement to a void method.what is the output of the program
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

See this: Programming With Assertions. It says:
The second form of the assertion statement is:

assert Expression1 : Expression2 ;

where:
  • Expression1 is a boolean expression.
  • Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)



  • Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
    Scala Notes - My blog about Scala
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: assert
     
    Similar Threads
    Assertion
    Qn on assertion.
    two possible answers Q18 ch 4 page 282 from KB
    Assertion topic
    How to turn on assert in TextPad ?