21. Program
//Find Simply which method gives Compile Time Error ?
For Ex:- Method test1 will not give Error ! Now check other.
class A
{
public static void main(String[] args)
{
//1
int test1(boolean flag)
{
return 10;
}
//2
int test2(boolean flag)
{
if(flag)
{
return 100;
}
else
{
return 20;
}
}
//3
int test3(boolean flag)
{
if(flag)
{
return 10;
}
}
//4
int test4(boolean flag)
{
if(flag)
{
return 10;
}
return 20;
}
//5
int test5(boolean flag)
{
if(flag)
{
}
else
{
return 30;
}
}
//6
int test6(boolean flag)
{
if(flag)
{
}
else
{
return 20;
}
return 0;
}
//7
int test7(boolean flag)
{
if(flag)
{
return 100;
}
else
{
return 20;
}
return 0;
}
}
}
22. Program
//Find Simply which method gives Compile Time Error ?
For Ex:- Method test1 Will give Error ! Now check other.
class B
{
public static void main(String[] args)
{
//1
int test1(int i)
{
try
{
//Something
}
catch(NumberFormatException ex)
{
return 10;
}
}
//2
int test2(int i)
{
try
{
//Something
return 0;
}
catch(NumberFormatException ex)
{
return 10;
}
}
//3
int test3(int i)
{
try
{
//Something
}
catch(NumberFormatException ex)
{
}
return 10;
}
//4
int test4(int i)
{
try
{
//Something
}
catch(NumberFormatException ex)
{
return 10;
}
return 20;
}
//5
int test5(int i)
{
try
{
//Something
return 10;
}
catch(NumberFormatException ex)
{
}
}
//6
int test6(int i)
{
try
{
//Something
return 10;
}
catch(NumberFormatException ex)
{
}
return 30;
}
//7
int test7(int i)
{
try
{
//Something
return 100;
}
catch(NumberFormatException ex)
{
return 10;
}
return 20;
}
}
}