Java program interface variable recursive call problems

For this problems, Variable value is not initialize. its dependents on anther variable.


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

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation