Java Interfaces and Packages Mcqs
Our collections of Multiple choice questions and answers focuses on study of Java Interfaces and Packages. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Interfaces and Packages topic comprehensively.
Java Programming Mcqs
- Data Types Variables and Arrays Mcqs
- Exception Handling in Java Mcqs
- Interfaces and Packages Mcqs
- Java Classes and Methods Mcqs
- Java Event Handling Mcqs
- Java Inheritance Mcqs
- Java IO and Applets Mcqs
- java lang and java io Mcqs
- Java Language Fundamentals Mcqs
- Java Operators and Control Statements Mcqs
- java utilities Mcqs
- Miscellaneous Topics in Java Mcqs
- Multithreading in Java Mcqs
- Serialization and Networking Mcqs
- Session Management and JSP and Servlet Mcqs
- String Handling
Computer MCQS
Sciences MCQS
2.
Which of these is a mechanism for naming and visibility control of a class and its content?
Object
Packages
Interfaces
None of the Mentioned.
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
3.
Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
Public
Protected
No Modifier
All of the mentioned
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
4.
Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?
Public
Protected
Private
No Modifier
6.
Which of the following is an incorrect statement about packages?
Package defines a namespace in which classes are stored
A package can contain other package within it
Java uses file system directories to store packages
A package can be renamed without renaming the directory in which the classes are stored
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
7.
Which of the following package stores all the standard java classes?
Lang
Java
Util
Java.packages
8.
What is the output of this program?
package pkg;
class display
{
int x;
void show()
{
if (x > 1)
System.out.print(x + " ");
}
}
class packages
{
public static void main(String args[])
{
display[] arr=new display[3];
for(int i=0;i<3;i++)
arr[i]=new display();
arr[0].x = 0;
arr[1].x = 1;
arr[2].x = 2;
for (int i = 0; i < 3; ++i)
arr[i].show();
}
}
package pkg;
class display
{
int x;
void show()
{
if (x > 1)
System.out.print(x + " ");
}
}
class packages
{
public static void main(String args[])
{
display[] arr=new display[3];
for(int i=0;i<3;i++)
arr[i]=new display();
arr[0].x = 0;
arr[1].x = 1;
arr[2].x = 2;
for (int i = 0; i < 3; ++i)
arr[i].show();
}
}
0
1
2
0 1 2
9.
What is the output of this program?
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1, x);
System.out.println(s1);
}
}
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1, x);
System.out.println(s1);
}
}
Xello
Xxxxx
Hxllo
Hexlo
10.
What is the output of this program?
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World");
s1.insert(6 , "Good ");
System.out.println(s1);
}
}
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World");
s1.insert(6 , "Good ");
System.out.println(s1);
}
}
HelloGoodWorld
HellGoodoWorld
Compilation error
Runtime error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
11.
Which of these keywords is used to define interfaces in Java?
Interface
Interface
Intf
Intf
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
12.
Which of these access specifiers can be used for an interface?
Public
Protected
Private
All of the mentioned
13.
Which of these keywords is used by a class to use an interface defined previously?
Import
Import
Implements
Implements
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
14.
Which of the following is the correct way of implementing an interface salary by class manager?
Class manager extends salary {}
Class manager implements salary {}
Class manager imports salary {}
None of the mentioned
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
15.
What is the output of this program?
interface calculate
{
void cal(int item);
}
class display implements calculate
{
int x;
public void cal(int item)
{
x = item * item;
}
}
class interfaces
{
public static void main(String args[])
{
display arr = new display;
arr.x = 0;
arr.cal(2);
System.out.print(arr.x);
}
}
interface calculate
{
void cal(int item);
}
class display implements calculate
{
int x;
public void cal(int item)
{
x = item * item;
}
}
class interfaces
{
public static void main(String args[])
{
display arr = new display;
arr.x = 0;
arr.cal(2);
System.out.print(arr.x);
}
}
0
2
4
None of the mentioned
16.
What is the output of this program?
interface calculate
{
void cal(int item);
}
class displayA implements calculate
{
int x;
public void cal(int item)
{
x = item * item;
}
}
class displayB implements calculate
{
int x;
public void cal(int item)
{
x = item / item;
}
}
class interfaces
{
public static void main(String args[])
{
displayA arr1 = new displayA;
displayB arr2 = new displayB;
arr1.x = 0;
arr2.x = 0;
arr1.cal(2);
arr2.cal(2);
System.out.print(arr1.x + " " + arr2.x);
}
}
interface calculate
{
void cal(int item);
}
class displayA implements calculate
{
int x;
public void cal(int item)
{
x = item * item;
}
}
class displayB implements calculate
{
int x;
public void cal(int item)
{
x = item / item;
}
}
class interfaces
{
public static void main(String args[])
{
displayA arr1 = new displayA;
displayB arr2 = new displayB;
arr1.x = 0;
arr2.x = 0;
arr1.cal(2);
arr2.cal(2);
System.out.print(arr1.x + " " + arr2.x);
}
}
0 0
2 2
4 1
1 4