TOTAL QS = 18Time [ 00 : 00 : 00 ]
00:00:00

Java Access Modifiers Basics Online Practice Test 1

Instructions

Total Questions: 18

Total Minutes: 18

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on the basics of Java Access Modifiers. This practice test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics.

Go through Java Theory Notes on Access Modifiers before attempting this test.

All the Best

Challenge SCORE

0 / 18

Take This Exam
1) Which are access modifiers below in Java?
2) What is an access modifier in Java?
3) Which is the keyword used to specify the DEFAULT access modifier in java?
4) Which is the less restrictive access modifier in Java?
5) Which is the most restrictive access modifier in Java?
6) Is it possible to combine more than one access modifier in Java?
7) Choose the correct Java code snippet with access modifiers below?
8) Can you access a default member of a class from a class of outside current package in Java?
9) Choose the correct statement about access modifiers in Java.
10) To access a protected variable or method of a Class outside the package, you need to ____ in Java.
11) What is the output of the Java program with access modifiers?
package apartment1;

public class Class101
{
  public String colour = "BLUE";
}


package apartment2;
import apartment1;

public class Apartment2Flat102
{
  public static void main(String[] args)
  {
    Class101 flat = new Class101();
    System.out.println(flat.colour);
  }
}
12) What is the output of the below Java Code Snippet with access modifiers?
package package1;

public class Forest {
int area = 10;//sq. km
}


package package1;

public class SmallForest
{
  public static void main(String[] args)
  {
    Forest fr = new Forest();
    System.out.println("Area = " + fr.area);
  }
}
13) What is the output of the Java code snippet with default access modifier?
package package1;

public class Bug {
int legs = 4;
}


package package2;
import package1.Bug;

public class BugTest extends Bug
{
  public static void main(String[] args)
  {
    Bug bug = new Bug();
    System.out.println("Bug Legs = " + bug.legs);
  }
}
14) What is the output of the Java code snippet with PROTECTED access modifier?
package package1;

public class Parent
{
  protected void showProperty()
  {
    System.out.println("10 million");
  }
}


package package2;
import package1.*;

public class Children extends Parent
{
  void show()
  {
    showProperty();
  }
  public static void main(String[] args)
  {
    Children chil = new Children();
    chil.show();
  }
}
15) What is the output of the Java code with PRIVATE access modifier?
package package1;
public class Factory
{
  private void run()
  {
    System.out.println("Running factory");
  }
}


package package1;
public class FactoryTest
{
  void callFactory()
  {
    Factory fac2 = new Factory();
    fac2.run();
  }
  public static void main(String[] args)
  {
    Factory fac1 = new Factory();
    fac.run();
  }
}
a
16) In Java, a PROTECTED variable or method of a Super class can not be accessed from a STATIC method of Subclass of different PACKAGE. State TRUE or FALSE.
17) What is the output of the Java program with PROTECTED access modifer?
package package1;

public class Milk
{
  protected int volume = 1000; //Liters
}

package package2;
import package1.Milk;
public class RoseMilk extends Milk
{
  public static void main(String[] args)
  {
    Milk object = new Milk();
    System.out.println(object.volume);
  }
}
18) What is the output of the Java code with PROTECTED access modifier?
package package1;
public class Plant
{
  protected void showHeight()
  {
    System.out.println("50 meters");
  }
}


package package2;
import package1.Plant;

public class Tree extends Plant
{
  public static void main(String[] args)
  {
    Tree tree = new Tree();
    tree.showHeight();
  }
}

Open Certification Helper Popup Reset Popup