Core Java Technical Test on Access Modifiers

Core Java Technical Test:  This Core Java Technical Test on Access Modifiers 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 Access Modifiers in Java.


1. What is the output of following code?
package p1 ;
public class First
{
protected void check()
{
System.out.println(“Checking”);
}
}

package p2 ;
import p1.First ;
class Second extends First
{
public static void main(String[] args)
{
First obj = new First();
obj.checking();
}
}

 
 
 
 

2. What is the output of following code?
private class Test
{
static int a=10 ;
public static void main(String[] args)
{
System.out.println(“private class”);
}
static
{
System.out.println(Test.a);
}
}

 

 
 
 
 

3. What is the output of following code?
package p1 ;
public class First
{
void check()
{
System.out.println(“Checking”);
}
}

package p2 ;
import p1.First ;
class Second
{
public static void main(String[] args)
{
First obj = new First();
obj.checking();
}
}

 

 
 
 
 

4. What is the output of following code?
class Test
{
static
{
System.out.println(“Block”);
}
}

 

 
 
 
 

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

 
 
 
 

6. What is the output of following code?
class Test
{
static
{
int a =10 ;
System.out.println(a);
}
public static void main(String args[ ])
{
System.out.println(“Main”);
System.out.println(a);
}
private static int a = 10 ;
}

 
 
 
 

7. What is the output if both the classes belong to same package?
class First
{
static int a=100 ;
}
class Second
{
public static void main(String[] args)
{
System.out.println(First.a);
}
}

 

 
 
 
 

8. What is the output of following application ?
package p1 ;
public class First
{
static
{
System.out.println(“First class”);
}
public static int a=100 ;
}

package p2 ;
import p1.First ;
class Second
{
public static void main(String[] args)
{
System.out.println(First.a);
}
}

 

 
 
 
 

9. What is the output of following application ?
import java.lang.System ;
class System
{
public static void main(String args[ ])
{
java.lang.System.out.println(“Main”);
}
}

 

 
 
 
 

10. What is the output of following application ?
package p1 ;
public class First
{
protected void check()
{
System.out.println(“Checking”);
}
}

package p2 ;
class Second extends First
{
public static void main(String[] args)
{
p1.First obj = new p1.First();
obj.checking();
}
}

 
 
 
 

Question 1 of 10

Share this