Quiz
07 Avulso
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (9)
1What will be the result ofattempting to compile and run the following program?
class TestClass{
public static void main( String args[ ] ) {
boolean b = false;
int i = 1;
do{
i++ ;
} while ( b = ! b) ;
System. out. println( i ) ;
}
}- AThe code will fail to compile, 'while' has an invalid condition expression.
- BIt will compile but will throw an exception at runtime.
- CIt will print 3.
- DIt will go in an infinite loop.
- EIt will print 1.
2What will the following code print?
boolean flag = true;
if( flag = false) {
System. out. println( " 1" ) ;
} else if( flag) {
System. out. println( " 2" ) ;
} else if( ! flag) {
System. out. println( " 3" ) ;
} else System. out. println( " 4" ) ;- A1
- B2
- C3
- D4
- ECompilation error.
3Which ofthe following are valid at line 1?
public class X{
//line 1: insert code here.
}- AString s;
- BString s = 'asdf';
- CString s = 'a';
- DString s = this.toString();
- EString s = asdf;
4Given the following class definition:
class A{
protected int i;
A( int i) { this. i = i; }
}/
/ 1 : Insert code here
Which ofthe following would be a valid class that can be inserted at //1 ?- Aclass B { }
- Bclass B extends A { }
- Cclass B extends A { B( ) { System. out. println( " i = " + i) ; } }
- Dclass B { B( ) { } }
5What will the following program print?
class LoopTest{
public static void main( String args[ ] ) {
int counter = 0;
outer:
for ( int i = 0; i < 3; i++) {
middle:
for ( int j = 0; j < 3; j ++) {
inner:
for ( int k = 0; k < 3; k++) {
if ( k - j > 0) {
break middle;
}c
ounter++;
}
}
}S
ystem. out. println( counter) ;
}
}- A2
- B3
- C6
- D7
- E9
6What letters, and in what order, will be printed when the following program is
compiled and run?
public class FinallyTest{
public static void main( String args[ ] ) throws Exception{
try{
m1( ) ;
System. out. println( " A" ) ;
}f
inally{
System. out. println( " B" ) ;
}S
ystem. out. println( " C" ) ;
}p
ublic static void m1( ) throws Exception { throw new Exception( ) ; }
}- A. It will print C and B, in that order.
- BIt will print A and B, in that order.
- CIt will print B and throw Exception.
- DIt will print A, B and C in that order.
- ECompile time error.
7class OverloadingTest{
void m1( int x) {
System. out. println( " m1 int" ) ;
}v
oid m1( double x) {
System. out. println( " m1 double" ) ;
}v
oid m1( String x) {
System. out. println( " m1 String" ) ;
}
}p
ublic class TestClass {
public static void main( String[ ] args) throws Exception {
OverloadingTest ot = new OverloadingTest( ) ;
ot. m1( 1. 0) ;
}
}Wha
t will be the output?- AIt will fail to compile.
- Bm1 int
- Cm1 double
- Dm1 String
8Given:
class Square {
private double side = 0;
String color;
public Square( double length) {
this. side = length;
}p
ublic double getSide( ) { return side; }
public void setSide( double side) { this. side = side; }
}p
ublic class TestClass {
public static void main( String[ ] args) throws Exception {
Square mysq = new Square( 10) ;
mysq. color = " red" ;
//set mysq' s side to 20
}
}Whi
ch ofthe following statements will set mysq's side to 20?- Amysq. side = 20;
- Bmysq = new Square( 20) ;
- Cmysq. setSide( 20) ;
- Dside = 20;
- ESquare. mysql. side = 20;
9What will be the result ofattempting to compile and run the following code?
public class PromotionTest{
public static void main( String args[ ] ) {
int i = 5;
float f = 5. 5f;
double d = 3. 8;
char c = ' a' ;
if ( i == f) c++;
if ( ( ( int) ( f + d) ) == ( ( int) f + ( int) d) ) c += 2;
System. out. println( c) ;
}
}- AThe code will fail to compile.
- BIt will print d.
- CIt will print c.
- DIt will print b.
- EIt will print a.
Informações
- Descrição
- Exam Mock EthuWare -OCA-SE-7-I Quiz sobre 07 Avulso, criado por Wong Fei Hung em 30-07-2017.
- Autor
- Wong Fei Hung
- Idioma
- Português
- Visualizações
- 0
- Etiquetas
- Avaliação
- Ainda sem avaliações Avalie este quiz