Core Java Technical Test on Static and Non-static Members

Core Java Technical Test: This Core Java Technical Test | Static and Non-static Members page is providing SCJP or OCJP certification level questions to test your java programming skills and help to clear all the technical interviews easily. This test is including the concept of class members like static and non-static members.


1. What is the output of following Code?
class Test
{
static
{
int a = 20 ;
System.out.println(Test.a);
Test.a = Test.a + a ;
}
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

 
 
 
 

2. What is the output of following Code?
class Test
{
int a ;
Test(int a)
{
a = this.a ;
this.a = a ;
}
public static void main(String[] args)
{
Test obj = new Test(10);
System.out.println(obj.a);
}
}

 
 
 
 

3. What is the output of following Code?
class Variables
{
public static void main(String[] args)
{
int a ;
System.out.println(a);
}
}

 
 
 
 

4. What is the output of following Code?
class Test
{
int a ;
Test(int x)
{
a = x + 20;
x = this.a + 10;
System.out.println(x);
}
public static void main(String[] args)
{
Test obj = new Test(10);
System.out.println(obj.a);
}
}

 
 
 
 

5. What is the output of following Code?
class Variables
{
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Variables.a);
System.out.println(a);
}
}

 
 
 
 

6. What is the output of following Code?
class Test
{
static int a = 50 ;
public static void main(String[] args)
{
System.out.println(Test.fun()+Test.a);
}
static int fun()
{
return Test.a+100;
}
}

 
 
 
 

7. What is the output of following Code?
class Test
{
static
{
int a = 20 ;
Test.a = Test.a + a ;
a = a + Test.a ;
Test.a = a + a ;
}
static int a = 10 ;
public static void main(String[] args)
{
System.out.println(Test.a);
}
}

 
 
 
 

8. What is the output of following Code?
class Variables
{
static
{
int a=10 ;
}
public static void main(String[] args)
{
System.out.println(Variables.a);
}
}

 
 
 
 

9. What is the output of following Code?
class Test
{
static int a ;
public static void main(String[] args)
{
Test.a = Test.m1(10);
System.out.println(Test.a);
}
static int m1(int a)
{
return Test.m2(20) + a ;
}
static int m2(int a)
{
return Test.a + Test.m3(20) ;
}
static int m3(int a)
{
return Test.a + a ;
}
}

 
 
 
 

10. What is the output of following Code?
class Variables
{
static
{
System.out.println(Variables.a);
}
public static void main(String[] args)
{
System.out.println(Variables.a);
}
static int a = 10 ;
}

 
 
 
 

Question 1 of 10

Share this