Write the output of the following program and explain your results. public class
ID: 3575715 • Letter: W
Question
Explanation / Answer
First undestand static function
1)Instance method requires an object of its class to be created before it can be called while static method doesn't require object creation.
2)If you wish to call static method of another class then you have to write class name while calling static method.
3)Staic method cannot use instance variables.
4) static function ae automtically called once the progam runs..
Ans7. As progrram runs ,static function is called and it prints
Not short circuit evaluation
And in main function If condition is not satisfies so goes in else and prints
case2
So overall ouput will be
Output:
Not short circuit evaluation
case2
Ans8.
output:
sum=15 func=17
Func will be called once as it is static. So vaalue of sum will be increment by 1.
As image is missing from end .Iam taking last line as below
System.out.printf("sum=%d func =%d ",sum,func(1,2) +sum);
As per above line it will print sum =15 func =17 ,as explained above this (func(1,2) +sum) will return 17 (1+16).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.