This Java programming language practice quiz assesses knowledge of interface implementation, exception handling, and class casting, among other topics. It is designed for learners looking to improve their Java skills and understand core concepts.
Foreach(x) System.out.println(z);
for(int z : x) System.out.println(z);
while( x.hasNext()) System.out.println( x.next());
For( int i=0; i< x.length; i++ ) System.out.println(x[i]);
Rate this question:
2
3
1 2
2 3
1 2 3
Compilation fails.
Au exceptional is thrown at runtime.
Rate this question:
The instance gets garbage collected.
The code on line 33 throws an exception.
The code on line 35 throws an exception.
The code on line 31 throws an exception.
The code on line 33 executes successfully.
Rate this question:
Alpha a = x;
Alpha a = x;
Foo f= (Delta)x;
Foo f= (Alpha)x;
Beta b = (Beta)(Alpha)x;
Rate this question:
Locale loc = Locale.getLocale(); System.out.println(loc.getDisplayCountry() + “ “+ df.format(d));
Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry() + “ “ + df.format(d));
Locale bc = Locale.getLocale(); System.out.println(loc.getDisplayCountry() + “ “+ df.setDateFormat(d));
Locale loc = Locale.getDefault(); System.out.println(loc.getDispbayCountry() + “ “+ df.setDateFormat(d));
Rate this question:
The class is fully encapsulated.
The code demonstrates polymorphism.
The ownerName variable breaks encapsulation.
The cardlD and limit variables break polymorphism.
The setCardlnformation method breaks encapsulation.
Rate this question:
Yen returns correct values.
Euro returns correct values.
An exception is thrown at runtime.
Yen and Euro both return correct values.
Compilation fails because of an error at line 25.
Compilation fails because of an error at line 30.
Rate this question:
class Man extends Dog { }
class Man implements Dog { }
Class Man { private BestFriend dog; }
Class Man { private Dog bestFriend; }
Class Man { private Dog }
Class Man { private BestFriend }
Rate this question:
The time to find the value from HashMap with a Person key depends on the size of the map.
Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.
The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
Rate this question:
Compilation fails due to an error in line 23.
Compilation fails due to an error in line 29.
A ClassCastException occurs in line 29.
A ClassCastException occurs in line 31.
The value of all four objects prints in natural order.
Rate this question:
Compilation fails.
An exception is thrown at runtime.
doStuffx = 6 main x = 6
DoStuffx = 5 main x = 5
DoStuffx = 5 main x = 6
doStuffx = 6 main x = 5
Rate this question:
import com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return Geodetics.DIAMETER/2.0; } }
Import static com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
import static com.sun.scjp.Geodetics. *; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
Package com.sun.scjp; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
Rate this question:
Direction d = NORTH;
Nav.Direction d = NORTH;
Direction d = Direction.NORTH;
Nav.Direction d = Nav.Direction.NORTH;
Rate this question:
Foo { public int bar() { return 1; } }
New Foo { public int bar() { return 1; } }
NewFoo() { public int bar(){return 1; } }
New class Foo { public int bar() { return 1; } }
Rate this question:
Compilation fails.
The code compiles and the output is 2.
If lines 16, 17 and 18 were removed, compilation would fail.
If lines 24, 25 and 26 were removed, compilation would fail.
If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.
Rate this question:
import sun.scjp.Color.*;
Import static sun.scjp.Color.*;
Import sun.scjp.Color; import static sun.scjp.Color.*;
Import sun.scjp.*; import static sun.scjp.Color.*;
Import sun.scjp.Color; import static sun.scjp.Color.GREEN
public interface B extends A { }
public interface B implements A {}
Public interface B instanceOf A {}
Public interface B inheritsFrom A { }
Rate this question:
TestA
TestB
Compilation fails.
An exception is thrown at runtime.
Rate this question:
Test
Null
An exception is thrown at runtime.
Compilation fails because of an error in line 1.
Compilation fails because of an error in line 4.
Compilation fails because of an error in line 5.
Rate this question:
Shape s = new Shape(); s.setAnchor(10,10); s.draw();
Circle c = new Shape(); c.setAnchor(10,10); c.draw();
Shape s = new Circle(); s.setAnchor(10,10); s.draw();
Shape s = new Circle(); s->setAnchor(10,10); s->draw();
Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();
Double getSalesAmount() { return 1230.45; }
Public double getSalesAmount() { return 1230.45; }
private double getSalesAmount() { return 1230.45; }
Protected double getSalesAmount() { return 1230.45; }
Rate this question:
public class Employee extends Info implements Data { public void load() { /*do something*/ } }
S
public class Employee implements Info extends Data { public void load() { /*do something*/ } } C. public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
public class Employee implements Info extends Data { public void Data.load() { /*d something */ } public void load() { /*do something */ } }
Public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
. public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
Rate this question:
public class Circle implements Shape { private int radius; }
Public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
Blic abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius; public void draw() {/* code here */} }
Public abstract class Circle implements Shape { private int radius; public void draw() { / code here */ } }
Rate this question:
public class Session implements Runnable, Clonable { public void run(); public Object clone(); }
. public class Session extends Runnable, Clonable { public void run() { / do something */ } public Object clone() { / make a copy */ } }
. public class Session implements Runnable, Clonable { public void run() { / do something */ } public Object clone() { /* make a copy */ } }
. public abstract class Session implements Runnable, Clonable { public void run() { / do something */ } public Object clone() { /*make a copy */ } }
Public class Session implements Runnable, implements Clonable { public void run() { / do something */ } public Object clone() { / make a copy */ } }
Rate this question:
Quiz Review Timeline (Updated): Mar 22, 2023 +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.
Wait!
Here's an interesting quiz for you.