Core Java Technical Test on Class and Object Members

Core Java Technical Test: This Core Java Technical Test on Class and Object Members  page is providing SCJP or OCJP certification level questions to test your java programming skills and helpful to clear all the technical interviews easily. This test is including the concept of class members like static and object members.


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

 
 
 
 

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

 

 
 
 
 

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

 
 
 
 

4. What is the output of following Code?
class Variables
{
static int a = 10 ;
static
{
System.out.println(a);
}
}

 

 
 
 
 

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

 
 
 
 

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

 
 
 
 

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

 
 
 
 

8. 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 ;
public static void main(String[] args)
{
System.out.println(“Global a : “+Test.a);
}
}

 
 
 
 

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

 
 
 
 

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

 
 
 
 

Question 1 of 10

Share this