package project32; public class Docs{ // (1)INSERT CODE HERE } public class Lega
ID: 3651631 • Letter: P
Question
package project32;public class Docs{
// (1)INSERT CODE HERE
}
public class Legal extends Docs {public void activateLegal() { System.out.println("Legal"); } }
import project32.Legal;
class Testproject32 {
public static void main(String[] args) {
Legal l = new Legal(); l.activateLegal(); l.activateDoc();
}
}
/*
Q1: In order to make this code compile with no error, what needs to
be typed into line (1)?
Q2: Why are access modifiers important? Isn't labeling the Docs class
public enough? Why or why not?
Q3: What access do you have if a class is modified as public, but none
of its methods are?
*/
Explanation / Answer
1. public void activateDoc()
{
System.out.println("Doc");
}
2. Access modifiers are very important. In this case naming the class public did the job.
But there are scenarios where the classes and its members are to protected from use by other classes
or their members due to which they are declared private or protected.
3.Then the methods can be accesed only within that class only even if the class is public
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.