0
0
Javaprogramming~15 mins

Private 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 private variable named age of type int.

Java
private [1] age;
🎯 Drag options to blanks, or click blank then click option
Aint
BString
Cvoid
Dclass
Attempts:
3 left
2fill in blank
medium

Complete the code to create a private method named getAge that returns an int.

Java
private [1] getAge() { return age; }
🎯 Drag options to blanks, or click blank then click option
Avoid
Bint
CString
Dclass
Attempts:
3 left
3fill in blank
hard

Fix the error in the code by completing the blank to access the private variable name inside the class.

Java
public String getName() { return this.[1]; }
🎯 Drag options to blanks, or click blank then click option
Aname
BgetName
CName()
DName
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a private constructor that initializes the private variable id.

Java
private [1]([2] id) { this.id = id; }
🎯 Drag options to blanks, or click blank then click option
AMyClass
Bint
CString
Dvoid
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a private setter method named setScore that updates the private variable score.

Java
private [1] setScore([2] score) { this.[3] = score; }
🎯 Drag options to blanks, or click blank then click option
Avoid
Bint
Cscore
DString
Attempts:
3 left