Java program interface variable recursive call problems
For this problems, Variable value is not initialize. its dependents on anther variable.
Problem
Output:
3
1
2
Solution:
Problem
- interface Test{
- int a=Test3.c+1;
- }
- interface Test2{
- int b=Test.a+1;
- }
- interface Test3{
- int c=Test2.b+1;
- }
- public class InhTest{
- public static void main(String[] args) {
- System.out.println(Test.a);
- System.out.println(Test2.b);
- System.out.println(Test3.c);
- }
- }
Same problems with class
- class Test{
- static int a=new Test3().c+1;
- }
- class Test2{
- static int b=new Test().a+1;
- }
- class Test3{
- static int c=new Test2().b+1;
- }
- public class InhTest{
- public static void main(String[] args) {
- System.out.println(Test.a);
- System.out.println(Test2.b);
- System.out.println(Test3.c);
- }
- }
Output:
3
1
2
Solution:
Comments
Post a Comment