Select an option to see the answer and solution.
Interfaces and Abstract Classes
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
309
Questions
4/16
Page
Pick an option on a question to see the right answer and solution.
class Output
{
public static void main(String args[])
{
String str = "true false";
boolean x = Boolean.parseBoolean(str);
System.out.print(x);
}
}Select an option to see the answer and solution.
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("/java/system");
System.out.print(obj.getName());
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class exception_handling
{
public static void main(String args[])
{
try
{
int a = 1;
int b = 10 / a;
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int c[] = {1};
c[8] = 9;
}
finally
{
System.out.print("A");
}
}
catch (NullPointerException e)
{
System.out.println("B");
}
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
import java.lang.reflect.*;
class Additional_packages
{
public static void main(String args[])
{
try
{
Class c = Class.forName("java.awt.Dimension");
Constructor constructors[] = c.getConstructors();
for (int i = 0; i < constructors.length; i++)
System.out.println(constructors[i]);
}
catch (Exception e)
{
System.out.print("Exception");
}
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
import java.io.*;
class Chararrayinput
{
public static void main(String[] args)
{
String obj = "abcdef";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0,length,c,0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 0, 3);
int i;
try
{
while ((i = input1.read()) != -1)
{
System.out.print((char)i);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 2, b, 1, a.length-2);
System.out.print(new String(a) + " " + new String(b));
}
}Select an option to see the answer and solution.
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("/java/system");
System.out.print(obj.getAbsolutePath());
}
}Select an option to see the answer and solution.
class Output
{
public static void main(String args[])
{
String str = "true";
boolean x = Boolean.valueOf(str);
System.out.print(x);
}
}Select an option to see the answer and solution.
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("/java/system");
System.out.print(obj.canWrite());
System.out.print(" " + obj.canRead());
}
}Select an option to see the answer and solution.
public class BoxDemo
{
public static <U> void addBox(U u,
java.util.List<Box<U>> boxes)
{
Box<U> box = new Box<>();
box.set(u);
boxes.add(box);
}
public static <U> void outputBoxes(java.util.List<Box<U>> boxes)
{
int counter = 0;
for (Box<U> box: boxes)
{
U boxContents = box.get();
System.out.println("[" + boxContents.toString() + "]");
counter++;
}
}
public static void main(String[] args)
{
java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
BoxDemo.<Integer>addBox(Integer.valueOf(0), listOfIntegerBoxes);
BoxDemo.outputBoxes(listOfIntegerBoxes);
}
}Select an option to see the answer and solution.
class Output
{
public static void main(String args[])
{
Integer i = new Integer(257);
float x = i.floatValue();
System.out.print(x);
}
}Select an option to see the answer and solution.