What Will Be The Output Of The Following Java Codep Pre #468
What will be the output of the following Java code?</p> <pre><code class="language-java"> //Create a directory/folder named p1, and save a Java file(Vehicle.java) package p1; public class Vehicle { protected int color; protected int speed = 10; } //Create another directory named p2, and save a Java file(ProtectedVariables.java) and make sure that two packages should be under the same root directory. //another program package p2; import p1.Vehicle; //import package p1 public class ProtectedVariables extends Vehicle { public static void main(String[] args) { ProtectedVariables p = new ProtectedVariables(); System.out.println("Speed: "+p.speed); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Class Components (Using Java) - Data Members - Quiz No.1.