Skip to main content

Declaration And Access Control — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Declaration And Access Control — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

Choose all the lines which if inserted independently instead of "//insert code here" will allow the following code to compile: public class Test{ public static void main(String args[]){ add(); add(1); add(1, 2); } // insert code here }

Question 2 of 40
★ FPSC ★ PPSC

What is the result of compiling and running the following code? class Base{ private Base(){ System.out.print("Base"); } } public class test extends Base{ public test(){ System.out.print("Derived"); } public static void main(String[] args){ new test(); } }

Question 3 of 40
★ FPSC ★ PPSC

What is the result of compiling and running the following code? public class Tester{ static int x = 4; public Tester(){ System.out.print(this.x); // line 1 Tester(); } public static void Tester(){ // line 2 System.out.print(this.x); // line 3 } public static void main(String... args){ // line 4 new Tester(); } }

Question 4 of 40
★ FPSC ★ PPSC

What is the result of compiling and running the following code? public class Tester{ static int x = 4; int y = 9; public Tester(){ System.out.print(this.x); // line 1 printVariables(); } public static void printVariables(){ System.out.print(x); // line 2 System.out.print(y); // line 3 } public static void main(String... args) { // line 4 new Tester(); } }

Question 5 of 40
★ FPSC ★ PPSC

Determine output: public class InitDemo{ static int i = demo(); static{ System.out.print(i); } InitDemo(){ System.out.print("hello1"); } public static void main(String... args){ System.out.print("Hello2"); } static int demo(){ System.out.print("InsideDemo"); return 10; } }

Question 6 of 40
★ FPSC ★ PPSC

A package is a collection of

Question 7 of 40
★ FPSC ★ PPSC

You have the following code in a file called Test.java class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} What will happen if you try to compile and run this?

Question 8 of 40
★ FPSC ★ PPSC

What is the output for the below code? public class A{ static{ System.out.println("static"); } { System.out.println("block"); } public A(){ System.out.println("A"); } public static void main(String[] args){ A a = new A(); } }

Question 9 of 40
★ FPSC ★ PPSC

What will be the output? public class Test{ public static void main(String[] args){ String value = "abc"; changeValue(value); System.out.println(value); } public static void changeValue(String a){ a = "xyz"; } }

Question 10 of 40
★ FPSC ★ PPSC

What will be the output for the below code? public class Test{ static{ int a = 5; } public static void main(String[] args){ System.out.println(a); } }

Question 11 of 40
★ FPSC ★ PPSC

Determine output: class A{ { System.out.print("b1 "); } public A(){ System.out.print("b2 "); } } class B extends A{ static{ System.out.print("r1 "); } public B(){ System.out.print("r2 "); } { System.out.print("r3 "); } static{ System.out.print("r4 "); } } public class Test extends B{ public static void main(String[] args){ System.out.print("pre "); new Test(); System.out.println("post "); } }

Question 12 of 40
★ FPSC ★ PPSC

What will be the output for the below code? static public class Test{ public static void main(String[] args){ char c = 'a'; switch(c){ case 65 : System.out.println("one");break; case 'a': System.out.println("two");break; case 3 : System.out.println("three"); } } }

Question 13 of 40
★ FPSC ★ PPSC

What will be the output after compiling and running following program code? public class Test{ static int a; public static void main(String[] args){ System.out.println("one"); call(1); } static void call(int a){ this.a=10; System.out.println("two "+a); } }

Question 14 of 40
★ FPSC ★ PPSC

What will be the output after the following program is compiled and executed? public class Test{ public static void main(String args[]){ int x = 10; x = myMethod(x--); System.out.print(x); } static int myMethod(final int x){ return x--; } }

Question 15 of 40
★ FPSC ★ PPSC

What is the default access modifier for class members in Java if no access modifier is specified?

Question 16 of 40
★ FPSC ★ PPSC

Which access modifier restricts a class member's visibility only to the same class and its subclasses?

Question 17 of 40
★ FPSC ★ PPSC

What keyword is used to declare a constant in Java, which is implicitly final and static?

Question 18 of 40
★ FPSC ★ PPSC

Which of the following access modifiers allows access to a class member from any class in any package?

Question 19 of 40
★ FPSC ★ PPSC

What is the access level of a class member with no access modifier specified in Java?

Question 20 of 40
★ FPSC ★ PPSC

In Java, which access modifier allows a method or variable to be accessed within the same package only?

Question 21 of 40
★ FPSC ★ PPSC

Which keyword is used to explicitly specify that a method cannot be overridden in a subclass?

Question 22 of 40
★ FPSC ★ PPSC

What is the default access modifier for a class in Java if no access modifier is specified?

Question 23 of 40
★ FPSC ★ PPSC

Which access modifier allows a class member to be accessed only within its own class and package?

Question 24 of 40
★ FPSC ★ PPSC

In Java, which access modifier allows a class member to be accessed from anywhere in the code?

Question 25 of 40
★ FPSC ★ PPSC

What keyword is used to declare a method that can be called without creating an instance of the class?

Question 26 of 40
★ FPSC ★ PPSC

Which of the following access modifiers restricts a method or variable's access to the same package only?

Question 27 of 40
★ FPSC ★ PPSC

In Java, what is the purpose of the static keyword when applied to a variable?

Question 28 of 40
★ FPSC ★ PPSC

Which keyword is used to define a superclass's method that is overridden by a subclass method?

Question 29 of 40
★ FPSC ★ PPSC

What is the access level of a class member declared as private in Java?

Question 30 of 40
★ FPSC ★ PPSC

Which access modifier allows a class member to be accessed within the same package and its subclasses?

Question 31 of 40
★ FPSC ★ PPSC

What is the keyword used to declare a class that cannot be instantiated and can only be extended?

Question 32 of 40
★ FPSC ★ PPSC

In Java, what access modifier is used to specify that a class member can be accessed only within its class?

Question 33 of 40
★ FPSC ★ PPSC

Which of the following is not an access modifier in Java?

Question 34 of 40
★ FPSC ★ PPSC

What access modifier allows a class member to be accessed from any class in the same package or any subclass?

Question 35 of 40
★ FPSC ★ PPSC

In Java, which access modifier allows a class member to be accessed from any class, even outside the package?

Question 36 of 40
★ FPSC ★ PPSC

What keyword is used to declare a method that is implemented in a subclass to provide a specific implementation?

Question 37 of 40
★ FPSC ★ PPSC

In Java, what is the purpose of the final keyword when applied to a method?

Question 38 of 40
★ FPSC ★ PPSC

Which access modifier allows a class member to be accessed from any class in the same package but not from outside?

Question 39 of 40
★ FPSC ★ PPSC

What keyword is used to declare a variable that can be accessed without creating an instance of the class?

Question 40 of 40
★ FPSC ★ PPSC

Which access modifier restricts a class member's visibility to only the same class, its package, and subclasses?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →