Quiz
01-Wrong-Questions-OCA-JAVA-SE
Dieses Quiz hat ein Zeitlimit und öffnet sich deshalb im gewohnten Player.
Fragen in diesem Quiz (13)
1Following is a supposedly robust method to parse an input for a float :
public float parseFloat( String s) {
float f = 0. 0f;
try{
f = Float. valueOf( s) . floatValue( ) ;
return f ;
}c
atch( NumberFormatException nfe) {
System. out. println( " Invalid input " + s) ;
f = Float. NaN ;
return f;
}f
inally { System. out. println( " finally" ) ; }
return f ;
}Whi
ch ofthe following statements about the above method are true??- AIfinput is " 0. 1" then it will return 0. 1 and print finally.
- BIfinput is " 0x. 1" then it will return Float. Nan and print Invalid Input 0x. 1
and finally. - CIfinput is " 1" then it will return 1. 0 and print finally.
- DIfinput is " 0x1" then it will return 0. 0 and print Invalid Input 0x1 and
finally. - EThe code will not compile.
210. QID - 2.1178 : Working with Methods
Which one ofthe following class definitions is/are a legal definition ofa class that
cannot be instantiated?
class Automobile{
abstract void honk( ) ; //( 1)
}a
bstract class Automobile{
void honk( ) ; //( 2)
}a
bstract class Automobile{
void honk( ) { } ; //( 3)
}a
bstract class Automobile{
abstract void honk( ) { } //( 4)
}a
bstract class Automobile{
abstract void honk( ) ; //( 5)
}- A1
- B2
- C3
- D4
- E5
3Which ofthe following statements are true?
- ASystem. out. println( 1 + 2 + " 3" ) ; would print 33.
- BSystem. out. println( " 1" + 2 + 3) ; would print 15.
- CSystem. out. println( 4 + 1. 0f) ; would print 5.0
- DSystem. out. println( 5/4) ; would print 1.25
- ESystem. out. println( ' a' + 1 ) ; would print b.
4Which ofthe following statements are true?
- Aprivate keyword can never be applied to a class.
- Bsynchronized keyword can never be applied to a class.
- Csynchronized keyword may be applied to a non-primitive variable.
- Dfinal keyword can never be applied to a class.
- EA final variable can be shadowed in a subclass.
5Which ofthese statements are true?
- AA static method can call other non-static methods in the same class by using the
'this' keyword. - BA class may contain both static and non-static variables and both static and nonstatic methods.
- CEach object ofa class has its own copy ofeach non-static member variable.
- DInstance methods may access local variables ofstatic methods.
- EAll methods in a class are implicitly passed a 'this' parameter when called.
- AA static method can call other non-static methods in the same class by using the
6Consider the following class:
public class PortConnector{
public PortConnector( int port) throws IOException{
. . . lot of valid code.
}.
. . other valid code.
}Y
ou want to write another class CleanConnector that extends from PortConnector.
Which ofthe following statements should hold true for CleanConnector class?- AIt is not possible to define CleanConnector that does not throw IOException at
instantiation. - BPortConnector class itselfis not valid because you cannot throw any exception
from a constructor. - CCleanConnector's constructor cannot throw any exception other than
IOException. - DCleanConnector's constructor cannot throw any exception other than subclass of
IOException. - ECleanConnector's constructor cannot throw any exception other than superclass of
IOException. - FNone ofthese.
- AIt is not possible to define CleanConnector that does not throw IOException at
7Consider the following classes :
class A{
public void mA( ) { } ;
}c
lass B extends A {
public void mA( ) { }
public void mB( ) { }
}c
lass C extends B {
public void mC( ) { }
}a
nd the following declarations:
A x = new B( ) ; B y = new B( ) ; B z = new C( ) ;
Which ofthe following calls are polymorphic calls?- Ax. mA( ) ;
- Bx. mB( ) ;
- Cy. mA( ) ;
- Dz. mC( ) ;
- Ez. mB( ) ;
8What will be the result ofattempting to compile and run the following program?
public class TestClass{
public static void main( String args[ ] ) {
Exception e = null;
throw e;
}
}- AThe code will fail to compile.
- BThe program will fail to compile, since it cannot throw a null.
- CThe program will compile without error and will throw an Exception when run.
- DThe program will compile without error and will throw
- EThe program will compile without error and will run and terminate without any
output.
9Consider the following code:
interface Flyer{ }
class Bird implements Flyer { }
class Eagle extends Bird { }
class Bat { }
public class TestClass {
public static void main( String[ ] args) {
Flyer f = new Eagle( ) ;
Eagle e = new Eagle( ) ;
Bat b = new Bat( ) ;
if( f instanceof Bird) System. out. println( " f is a Bird" ) ;
if( e instanceof Flyer) System. out. println( " e is a Flyer" ) ;
if( b instanceof Flyer) System. out. println( " f is a Bird" ) ;
}
}Wha
t will be printed when the above code is compiled and run?- AIt will not compile.
- BIt will throw an exception when run.
- Cfis a Bird
e is a Flyer - DD. fis a Bird
- Ee is a Flyer
10What will be the result ofattempting to compile and run the following program?
class TestClass{
public static void main( String args[ ] ) {
int i = 0;
for ( i=1 ; i<5 ; i++) continue; //( 1)
for ( i=0 ; ; i++) break; //( 2)
for ( ; i<5?false: true ; ) ; //( 3)
}
}- AThe code will compile without error and will terminate without problems when
run - BThe code will fail to compile, since the continue can't be used this way.
- CThe code will fail to compile, since the break can't be used this way
- DThe code will fail to compile, since the for statement in the line 2 is invalid.
- EThe code will compile without error but will never terminate.
- AThe code will compile without error and will terminate without problems when
11What is the result ofexecuting the following code when the value ofi is 5:
switch ( i) {
default:
case 1:
System. out. println( 1) ;
case 0:
System. out. println( 0) ;
case 2:
System. out. println( 2) ;
break;
case 3:
System. out. println( 3) ;
}- At will print 1 0 2
- BIt will print 1 0 2 3
- CIt will print 1 0
- DIt will print 1
- ENothing will be printed.
12Which ofthe following statements are true?
- AThe modulus operator % can only be used with integer operands.
- B& can have integral as well as boolean operands.
- CThe arithmetic operators *, / and % have the same level ofprecedence.
- D&& can have integer as well as boolean operands.
- E~ can have integer as well as boolean operands.
13Consider the following classes...
class Teacher{
void teach( String student) {
/* lots of code */
}
}c
lass Prof extends Teacher{
//1
}Whi
ch ofthe following methods can be inserted at line //1 ?- Apublic void teach( ) throws Exception
- Bprivate void teach( int i) throws Exception
- Cprotected void teach( String s)
- Dpublic final void teach( String s)
- Epublic abstract void teach( String s)
Informationen
- Beschreibung
- Wrong-Question-OCA-SE-I Quiz am 01-Wrong-Questions-OCA-JAVA-SE, erstellt von Wong Fei Hung am 02/08/2017.
- Autor
- Wong Fei Hung
- Sprache
- Português
- Aufrufe
- 1
- Verlauf
- Erstellt am 2 Aug 2017 · aktualisiert am 2 Aug 2017
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz