Given two files:
1. package com.mypkg; 2. public class MyClass { 3. void do1() { System.out.print("do1 "); } 4. protected void do2() { System.out.print("do2 "); } 5. public void do3() { System.out.print("do3 "); } 6. } /*from w ww . j a va2 s. c o m*/ 1. import com.mypkg.*; 2. public class UPS extends MyClass { 3. public static void main(String[] args) { 4. MyClass u = new MyClass(); 5. u.do1(); 6. u.do2(); 7. u.do3(); 8. } }
What is the result? (Choose all that apply.)
D and E are correct
Lines 5 and 6 will NOT compile.
If the protected method do2() was invoked through inheritance (for instance, "new UPS()
.do2();"), it would compile.