Return to site

JAVA CERTIFICATION QUESTION: Accessing public, private, protected, and default classes in Java

· java

Java’s four access control levels increase accessibility from private to default (which has no keyword), then to protected, and then to public.

Given the following:

package a;
public class Car {
    protected void drive() {System.out.print("Drive !");}
    void stop() {System.out.print("Stop !");}
}

 

And:

package b;
import a.Car;
public class Vehicle extends Car {
    public static void main(String[] args) {
        Vehicle v = new Vehicle();
        v.test(v);
    }
    private void test(Car obj) {
        // line n1
    }
}

 

Which line, when inserted individually at line n1, compiles successfully? Choose one.

A. obj.drive();

B. drive();

C. Compilation of the obj.stop();

D. Compilation of the stop();

 

 

 

 

 

 

·ꓭ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ