0
0
Javaprogramming~15 mins

Protected access modifier in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a protected variable named data.

Java
protected [1] data;
🎯 Drag options to blanks, or click blank then click option
Aint
Bpublic
Cclass
Dvoid
Attempts:
3 left
2fill in blank
medium

Complete the code to declare a protected method named showData that returns nothing.

Java
protected [1] showData() { }
🎯 Drag options to blanks, or click blank then click option
Aclass
Bint
Cvoid
DString
Attempts:
3 left
3fill in blank
hard

Fix the error in the code by completing the access modifier for the method display so it can be accessed by subclasses.

Java
[1] void display() { System.out.println("Hello"); }
🎯 Drag options to blanks, or click blank then click option
Aprivate
Bpublic
Cstatic
Dprotected
Attempts:
3 left
4fill in blank
hard

Fill both blanks to declare a protected constructor for class Example.

Java
class Example {
    [1] [2]() { }
}
🎯 Drag options to blanks, or click blank then click option
Aprotected
Bpublic
CExample
Dvoid
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a protected method named calculate that returns an integer and takes an integer parameter named value.

Java
protected [1] calculate([2] [3]) { return value * 2; }
🎯 Drag options to blanks, or click blank then click option
Aint
Cvalue
Dvoid
Attempts:
3 left