Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
In the world of Java, access modifiers act like bouncers at a club, controlling who gets to see and use the different parts (variables and methods) of your code. Ready to become an access modifier master? Dive into our interactive quiz and put your knowledge to the test! This isn’t your average snoozefest quiz.
Through a series of engaging challenges, you’ll explore the secret rules that determine who can see what, how classes interact with each other, and the best ways to keep your code safe and organized.
Whether you’re a newbie just starting your Java adventure or a coding veteran looking to polish your skills, this quiz will push you to think critically and solidify your understanding of access modifiers.
So, are you ready to embark on a thrilling quest to conquer this essential concept? Take the quiz now and unlock the secrets of access modifiers in Java! Let’s test your knowledge of Java Access Modifiers.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
What will be the output of the program ?
- protected class Message {
string text = “ DataFlair”;
void display () {
system.out.println(text);
}
}
public class Example {
public static void main ( String args [ ] )
{
Message object = new Message;
object,display();
}
}
CorrectIncorrect -
Question 2 of 15
2. Question
What will be the output of the program ?
addition.package;
class Addition {
int a , b , sum;
void add( int a , int b)
{
system.out.println(sum= a + b );
}
}
public class Example {
public static void main ( String args [ ] )
{
Addition obj = new Addition;
obj.add(99,1);
}
}
CorrectIncorrect -
Question 3 of 15
3. Question
What will be the error in the program ?
private class One {
private class Two {
}
}
CorrectIncorrect -
Question 4 of 15
4. Question
What will be the output of the program ?
class A {
private int a = 1;
private Void display ( ) {
system.out.println( This is a private method );
}
}
public class B {
public static void main ( String args [ ] )
{
A obj = new A;
Obj.a = 2;
system.out.println(a);
obj.display();
}
}
CorrectIncorrect -
Question 5 of 15
5. Question
Which access specifier is accessed only by their subclass and their class on having the same package ?
CorrectIncorrect -
Question 6 of 15
6. Question
What will be the output of the program ?
class Main{
public int n = 99;
public void data(){
System.out.println(“ARR Movie Name.”);
}
}
class PublicAccessSpecifier{
public static void main(String args[]){
Main obj=new Main();
System.out.println(obj.n);
obj.data();
}
}
CorrectIncorrect -
Question 7 of 15
7. Question
Which access specifier does the following program exhibit?
class Sample {
Int a = 100;
}
class AccessSpecifier {
public static void main( String args [ ] )
{
Sample obj = new Sample();
int number = obj.a;
system.out.println(“The Number of Branches DataFlair has is: “+number);
}
}
CorrectIncorrect -
Question 8 of 15
8. Question
Which of the following is the correct syntax for a private access specifier?
CorrectIncorrect -
Question 9 of 15
9. Question
What will be the output of the program ?
public class Webservices {
private String name = “Data”;
public static void main ( String args [ ] )
{
Webservices s = new Webservices ();
s.name = “DataFlair”;
system.out.println(name);
}
}
CorrectIncorrect -
Question 10 of 15
10. Question
What is the error in the program ?
public class Student {
public name;
private Student() {
}public class StudentTest {
public static void main ( String args [ ] ) {
Student s = new Student ();
}
}
CorrectIncorrect -
Question 11 of 15
11. Question
How to access public sub-class fields ?
CorrectIncorrect -
Question 12 of 15
12. Question
Where should the object be created to get the output?
class A{
private int data=40;
private void msg(){
system.out.println(“Hello java”);
}
public static void main ( String args [ ] ) {
}
}
public class Simple{
public static void main(String args [ ] ) {
}
}
CorrectIncorrect -
Question 13 of 15
13. Question
Which is the least restrictive specifier method in Java?
CorrectIncorrect -
Question 14 of 15
14. Question
First and Second are two programs with different packages. Second is a subclass of First. What should be imported to Second class to get the output ?
package p1
public class First {
protected void display()
{
System.out.println(“DataFlair”);
}
}
Package p2
class Second extends First {
public static void main(String args [ ] )
{
Second object = new Second();
object.display();
}
}
CorrectIncorrect -
Question 15 of 15
15. Question
To perform the concept of Inheritance, which access specifier should be used ?
CorrectIncorrect
Summary:
Congratulations on conquering the Java access modifiers quiz! You’ve successfully navigated your way through a world of visibility, understanding how code can be seen and used by different parts of your program.
You’ve also become a pro at figuring out the relationships between classes and how access modifiers help you control that connection. But this is just the first step on your Java mastery path!
Remember, access modifiers are like the guardians of your code, ensuring only the right pieces have access and things stay organized. By using them effectively, you’ll build strong, secure, and well-designed Java applications.
Don’t stop here! Keep practising and exploring more advanced techniques. There’s a whole world of Java challenges waiting for you to tackle. Stay tuned because more exciting adventures in the land of Java are just around the corner!
