Explore topic-wise MCQs in Java Programming.

This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the correct option with regards to below snippet?
interface NewCustomer 
{
}
class RegCustomer implements NewCustomer
{
}
class QuickCustomer implements NewCustomer
{
}

A. QuickCustomer can be replaced with RegCustomer
B. We can instantiate objects of NewCustomer
C. NewCustomer can be replaced with RegCustomer
D. RegCustomer can be replaced with QuickCustomer
E. None of these
Answer» D. RegCustomer can be replaced with QuickCustomer
2.

What is the output of this program?
interface Calculation 
{
int var = 0;
void calculate(int num);
}

class display implements Calculation
{
int p;
public void calculate(int num)
{
if (num<2)
{
p = var;
}
else
{
p = num * num;
}
}
}

public class interfaces_Example
{

public static void main(String args[])
{
display[] array = new display[4];

for(int k=0; k<4; k++)
array[k] = new display();
array[0].calculate(0);
array[1].calculate(2);
array[2].calculate(4);
System.out.print(array[0].p+" " + array[1].p + " " + array[2].p);
}
}

A. 0 4 16
B. 4 0 16
C. 16 0 4
D. Compilation Error
E. Runtime Error
Answer» B. 4 0 16
3.

What is the output of this program?
interface Calculation
{
void calculate(int item);
}
class display0 implements Calculation
{
int p;
public void calculate(int num)
{
p = num * num;
}
}

class display1 implements Calculation
{
int p;
public void calculate(int num)
{
p = num / num;
}
}

public class interfaces_Example
{
public static void main(String args[])
{
display0 object0 = new display0();
display1 object1 = new display1();
object0.p = 0;
object1.p = 0;
object0.calculate(5);
object1.calculate(5);
System.out.print(object0.p + " " + object1.p);
}
}

A. 25 1
B. 1 25
C. 0 5
D. 5 0
E. None of these
Answer» B. 1 25
4.

What is the output of this program?
interface calculation
{
void calculate(int Num);
}
class display implements calculation
{
int p;
public void calculate(int Num)
{
p = Num * Num;
}
}

public class interfaces_Example
{
public static void main(String args[])
{
display object = new display();
object.p = 0;
object.calculate(4);
System.out.print(object.p);
}
}

A. 0
B. 4
C. 16
D. Compilation Error
E. Runtime Error
Answer» D. Compilation Error
5.

What is the output of below snippet?
try (InputStream is = ...) 
{
// do stuff with is...
}
catch (IOException e)
{
// handle exception
}

A. Runs successfully
B. Compilation Error
C. IOException
D. Runtime Error
E. None of these
Answer» B. Compilation Error
6.

Does close() implicitly flush() the stream.

A. False
B. True
C. NA
D. NA
E. NA
Answer» C. NA
7.

Can abstract keyword be used with constructor, Initialization Block, Instance Initialization and Static Initialization Block.

A. False
B. True
C. NA
D. NA
E. NA
Answer» C. NA
8.

Which of the following is the correct way of implementing an interface salary by class company?

A. class company imports salary {}
B. class company extends salary {}
C. class company implements salary {}
D. All of above
E. None of these
Answer» D. All of above
9.

Which of the following is the correct way of implementing an interface N by class M?

A. class M imports N{}
B. class M extends N{}
C. class M implements N{}
D. All of above
E. None of these
Answer» D. All of above