0
0
Javaprogramming~15 mins

Default 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 class with default access modifier.

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

Complete the code to declare a method with default access modifier inside a class.

Java
class Test {
    [1] void show() {
        System.out.println("Show method");
    }
}
🎯 Drag options to blanks, or click blank then click option
A(no keyword)
Bpublic
Cprivate
Dprotected
Attempts:
3 left
3fill in blank
hard

Fix the error in the code by choosing the correct access modifier for the class to have default access.

Java
[1] class Sample {
    void test() {
        System.out.println("Test method");
    }
}
🎯 Drag options to blanks, or click blank then click option
Apublic
B(no keyword)
Cprivate
Dprotected
Attempts:
3 left
4fill in blank
hard

Fill both blanks to declare a variable and a method with default access modifier inside a class.

Java
class Example {
    [1] int number;
    [2] void display() {
        System.out.println(number);
    }
}
🎯 Drag options to blanks, or click blank then click option
A(no keyword)
Bpublic
Cprivate
Dprotected
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to declare a class, a variable, and a method with default access modifier.

Java
[1] class Data {
    [2] int value;
    [3] void print() {
        System.out.println(value);
    }
}
🎯 Drag options to blanks, or click blank then click option
A(no keyword)
Bpublic
Cprivate
Dprotected
Attempts:
3 left