Rumman Ansari
Home
Blog
Courses
Paid Courses
Authentication
D365 F&O MCQ Questions - X++ Programming Language MCQ
Digital Productivity
GH-300: GitHub Copilot
ICSE Computer Applications Class 10 – Previous Year Question Papers & Solutions
Java Fundamentals: Building Strong Foundations
Mastering JavaScript: From Fundamentals to Advanced Concepts
MB-500: Microsoft Dynamics 365: Finance and Operations Apps Developer
X++ Programming Fundamentals - D365 F&O Technical
X++ Programming Language
Free Courses
AB-730: Microsoft Certified: AI Business Professional
AJAX
AngularJS
Arithmetic Aptitude
Artificial intelligence
Automata Theory
AZ-400: Designing and Implementing Microsoft DevOps Solutions
Azure DevOps for Beginners
Bangla to English
Biography
Biology
Bootstrap 4
C Programming Language
C Programming Language Video Bangla
C# Programming Language
C++ language
Competitive Exam
Computer Awareness
Computer Fundamentals
Computer Network
Computer Science and Engineering
Continuous Deployment
Continuous Integration
CSS
Current Affairs
Data Structure
Database Management System
Digital Logic
Education
Electrical Engineering
English
English Grammar
General Aptitude
Geography
History
HTML 5
Important Days and Dates
Interview Questions
ISC - COMPUTER SCIENCE - XI
Islam
Java Programming Language
JavaScript
Leadership behavior and Culture
Logical Fallacy
Machine Learning
Mastering HTML: From Fundamentals to Advanced Concepts
Mathematics
Mathematics for Programming
Mathematics in Bangla - Class 5
MB-310: Microsoft Certified: Dynamics 365 Finance Functional Consultant Associate
MB-330: Microsoft Certified: Dynamics 365 Supply Chain Management Functional Consultant Associate
MB-700: Microsoft Dynamics 365: Finance and Operations Apps Solution Architect
MB-920: Microsoft Dynamics 365 Fundamentals (ERP)
Microservices Architecture
Microsoft Azure
Microsoft Excel - Bangla
Mindwork games
Miscellaneous Topics
Misconceptions about Islam
MySQL
Neural Networks and Deep Learning
NPM - Package Manager
Pakistan Geography
Photoshop
PHP
Programming Language
Prompt Engineering
Puzzles
Python
R Programming Language
ReactJS
Science
Social Science
SQL
SQLite
Tamil Nadu State board (Class 10)
Technical MCQs
Technical Short Answers
TypeScript - JavaScript's Superset
UGC NET, SET
User Experience
Verbal and Reasoning
Vue JS
অতীত ও ঐতিহ্য: অষ্টম শ্রেণীর: পশ্চিমবঙ্গ মধ্যশিক্ষা পর্ষদ
অর্থনীতি
আরবী ভাষা কোর্স - Diploma in Arabic language
ইতিহাস
ইতিহাস ও পরিবেশ: দশম শ্রেণি: পশ্চিমবঙ্গ মধ্যশিক্ষা পর্ষদ
ইসলামিক বই
ইসলামে আকীকা
ইসলামে নারী
এসো আরবী শিখি
কুরআন
খাদ্য, পুষ্টি ও খাদ্যের উপাদান
জীবনবিজ্ঞান ও পরিবেশ (দশম)
তাহারাত কুইজ প্রতিযোগিতা
নবীদের কাহিনী - The story of the prophets
পরিবেশ ও বিজ্ঞান
প্যারেন্টিং - Parenting
প্রচলিত ভুল বিষয়ে প্রতিযোগিতা টেস্ট কুইজ
প্রশ্নোত্তরে ইসলামী জ্ঞান
বাংলা ইসলামিক কুইজ - Bangla Islamic Quiz
বাংলা সাহিত্য
ব্যক্তিগত উন্নয়ন (Personal Development)
ভূগোল
মডার্ন কম্পিউটার অ্যাপ্লিকেশন - একাদশ শ্রেণী
মডার্ন কম্পিউটার অ্যাপ্লিকেশন - দ্বাদশ শ্রেণী
লেখক এবং কবি
শয়তান পরিচিতি
সংক্ষিপ্ত জীবনী
সাধারণ জ্ঞান
সাহাবীদের জীবনী
সীরাত প্রতিযোগিতার প্রশ্ন ও উত্তরসমূহ
Guest
Profile
Logout
Green
Light
Dark
Declaration and Access Control in Java
Answer all questions carefully. After submission, you will see a detailed result and answer review.
Question 1
A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?
A.
Declare the method with the keyword public.
B.
Declare the method with the keyword private.
C.
Declare the method with the keyword protected.
D.
Do not declare the method with any accessibility modifiers.
Question 2
What can directly access and change the value of the variable qusNo? <pre class="prettyprint"> package com.mypackage; public class Test{ private int qusNo = 100; } </pre>
A.
Only the Test class.
B.
Any class.
C.
Any class in com.mypackage package.
D.
Any class that extends Test.
Question 3
Consider the following two classes declared and defined in two different packages, what can be added in class B to form what considered a correct access to class A from main() method of class B? <pre class="prettyprint"> package subPackage; public class A { } package anotherPackage; // line 1 public class B{ public static void main(String[] args){ // line 2 } } </pre> 1. At line1 add noting; At line2 add: new A();<br />2. At line 1 add: import package.*; at line
A.
1 and 2
B.
2 and 4
C.
3 and 4
D.
1 and 3
Question 4
Choose all the lines which if inserted independently instead of "//insert code here" will allow the following code to compile: <pre class="prettyprint"> public class Test{ public static void main(String args[]){ add(); add(1); add(1, 2); } // insert code here } </pre>
A.
void add(Integer... args){}
B.
static void add(int... args, int y){}
C.
static void add(int args...){}
D.
static void add(int...args){}
Question 5
What will be the output for the below code? <pre class="prettyprint"> public class Test{ static{ int a = 5; } public static void main(String[] args){ System.out.println(a); } } </pre>
A.
Compile with error
B.
5
C.
0
D.
Runtime Exception
Question 6
Which statements are most accurate regarding the following classes? <pre class="prettyprint"> class A{ private int i; protected int j; } class B extends A{ private int k; protected int m; } </pre>
A.
An object of B contains data fields i, j, k, m.
B.
An object of B contains data fields j, k, m.
C.
An object of B contains data fields j, m.
D.
An object of B contains data fields k, m.
Question 7
What will be the output for the below code? <pre class="prettyprint"> 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"); } } } </pre>
A.
one
B.
two
C.
Compile error - char can't be permitted in switch statement.
D.
Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted.
Question 8
Choose the correct statement <pre class="prettyprint"> public class Circle{ private double radius; public Circle(double radius){ radius = radius; } } </pre>
A.
The program has a compilation error because it does not have a main method.
B.
The program will compile, but we cannot create an object of Circle with a specified radius. The object will always have radius 0.
C.
The program has a compilation error because we cannot assign radius to radius.
D.
The program does not compile because Circle does not have a default constructor.
Question 9
You have the following code in a file called Test.java <pre class="prettyprint"> class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} </pre> What will happen if you try to compile and run this?
A.
It will fail to compile.
B.
Runtime error
C.
Compiles and runs with no output.
D.
Compiles and runs printing
Question 10
Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.
A.
static
B.
final
C.
abstract
D.
native
Submit Quiz