Quiz
05-Objectives-Wise-Java-Basics
Dieses Quiz hat ein Zeitlimit und öffnet sich deshalb im gewohnten Player.
Fragen in diesem Quiz (20)
1Note: This question may be considered too advanced for this exam. What will the
code shown below print when compiled and run with the following command line?
j ava WarZone self
interface XMen {
void shoot( String a) ;
}p
ublic class WarZone {
public static void main( String[ ] args) {
XMen x = null;
if( args. length( ) > 0) {
x = new XMen( ) {
public void shoot( String s) {
for( int i=0; i<s. length; i++) {
System. out. println( " shot : " +s. charAt( i) ) ;
}
}
} ;
}i
f( x ! = null) {
x. shoot( args[ 0] ) ;
}
}
}- AIt will not compile because interface XMen cannot be instantiated.
- BIt will print shot : 4 times, one at each line.
- CIt will print "shot : s", "shot : e", "shot : l", "shot : f" one by one on 4
lines. - DIt will compile but will throw an exception at runtime.
- ENone ofthese options is correct.
2What would be the result ofattempting to compile and run the following program?
class TestClass{
static TestClass ref;
String[ ] arguments;
public static void main( String args[ ] ) {
ref = new TestClass( ) ;
ref. func( args) ;
}p
ublic void func( String[ ] args) {
ref. arguments = args;
}
}- AThe program will fail to compile, since the static method main is trying to call the
non-static method func. - BThe program will fail to compile, since the non-static method func cannot access
the static member variable ref. - CThe program will fail to compile, since the argument args passed to the static
method main cannot be passed on to the non-static method func. - DThe program will fail to compile, since method func is trying to assign to the nonstatic member variable 'arguments' through the static member variable ref.
- EThe program will compile and run successfully.
- AThe program will fail to compile, since the static method main is trying to call the
3Which ofthe following statements is correct?
- Anew, delete and goto are keywords in the Java language
- Btry, catch and thrown are keywords in the Java language
- Cstatic, unsigned and long are keywords in the Java language
- Dexit, class and while are keywords in the Java language
- Ereturn, goto and default are keywords in the Java language
4Which ofthe following lines can be inserted at line 1 to make the program run?
//line 1
public class TestClass{
public static void main( String[ ] args) {
PrintWriter pw = new PrintWriter( System. out) ;
OutputStreamWriter osw = new OutputStreamWriter( System. out
) ;
pw. print( " hello" ) ;
}
}A
ssume that PrintWriter and OutputStreamWriter are valid classes in j ava. io
package.- Aimport j ava. lang. *;
- Bimport j ava. io. *;
- Cimport j ava. io. OutputStreamWriter;
- Dinclude j ava. io. *;
- Einclude j ava. lang. System;
5Given the following program, which statement is true?
class SomeClass{
public static void main( String args[ ] ) {
if ( args. length == 0 ) {
System. out. println( " no arguments" ) ;
}e
lse{
System. out. println( args. length + " arguments" ) ;
}
}
}- AThe program will fail to compile.
- BThe program will throw a NullPointerException when run with zero arguments.
- CThe program will print no arguments and 1 arguments when called with zero
and one arguments. - DThe program will print no arguments and 2 arguments when called with zero
and one arguments. - EThe program will print no arguments and 3 arguments when called with zero
and one arguments.
6Consider the following two classes defined in two .java files.
//in file /root/com/foo/X. j ava
package com. foo;
public class X{
public static int LOGICID = 10;
public void apply( int i) {
System. out. println( " applied" ) ;
}
}/
/in file /root/com/bar/Y. j ava
package com. bar;
//1 <== INSERT STATEMENT( s) HERE
public class Y{
public static void main( String[ ] args) {
System. out. println( X. LOGICID) ;
}
}Wha
t should be inserted at //1 so that Y.java can compile without any error?- Aimport static X;
- Bimport static com. foo. *;
- Cimport static com. foo. X. *;
- Dimport com. foo. *;
- Eimport com. foo. X. LOGICID;
7Note: Option 4 ofthis question may be considered too advanced for this exam.
Which lines ofcode will not be acceptable to the compiler?
import j ava. *; //1
public abstract class InternalLogic //2
{
float density = 20. 0; //3
public class Doer //4
{
void do( ) //5
{
//lot of valid code.
}
}
}- A1
- B2
- C3
- D4
- E5
8Which ofthe following keywords may occur multiple times in a Java source file?
- Aimport
- Bclass
- Cprivate
- Dpackage
- Epublic
9Given the following set ofmember declarations, which ofthe following is true?
int a; // ( 1)
static int a; // ( 2)
int f( ) { return a; } // ( 3)
static int f( ) { return a; } // ( 4)- ADeclarations (1) and (3) cannot occur in the same class definition.
- BDeclarations (2) and (4) cannot occur in the same class definition.
- CDeclarations (1) and (4) cannot occur in the same class definition.
- DDeclarations (2) and (3) cannot occur in the same class definition.
- EDeclarations (1) and (2) cannot occur in the same class definition.
10Consider the following class :
public class Parser{
public static void main( String[ ] args) {
try{
int i = 0;
i = Integer. parseInt( args[ 0] ) ;
}c
atch( NumberFormatException e) {
System. out. println( " Problem in " + i ) ;
}
}
}Wha
t will happen ifit is run with the following command line:
j ava Parser one- AIt will print Problem in 0
- BIt will throw an exception and end without printing anything.
- CIt will not even compile.
- DIt will not print anything ifthe argument is '1' instead of'one'.
- ENone ofthe above.
11What will be result ofattempting to compile this class?
import j ava. util. *;
package test;
public class TestClass{
public OtherClass oc = new OtherClass( ) ;
}c
lass OtherClass{
int value;
}- AThe class will fail to compile, since the class OtherClass is used before it is
defined. - BThere is no problem with the code.
- CThe class will fail to compile, since the class OtherClass must be defined in a file
called OtherClass.java - DThe class will fail to compile .
- ENone ofthe above.
- AThe class will fail to compile, since the class OtherClass is used before it is
12Which one ofthese is a proper definition ofa class TestClass that cannot be subclassed?
- Afinal class TestClass { }
- Babstract class TestClass { }
- Cnative class TestClass { }
- Dstatic class TestClass { }
- Eprivate class TestClass { }
13Consider the following two classes defined in two java source files.
//in file /root/com/foo/X. j ava
package com. foo;
public class X{
public static int LOGICID = 10;
public void apply( int i) {
System. out. println( " applied" ) ;
}
}/
/in file /root/com/bar/Y. j ava
package com. bar;
//1 <== INSERT STATEMENT(s) HERE
public class Y{
public static void main( String[ ] args) {
X x = new X( ) ;
x. apply( LOGICID) ;
}
}Wha
t should be inserted at //1 so that Y.java can compile without any error?- Aimport static X;
- Bimport static com. foo. *;
- Cimport static com. foo. X. *;
- Dimport com. foo. *;
- Eimport com. foo. X. LOGICID;
14Which method declarations will enable a class to be run as a standalone program?
- Astatic void main( String args[ ] )
- Bpublic void static main( String args[ ] )
- Cpublic static main( String[ ] argv)
- Dfinal public static void main( String [ ] array)
- Epublic static void main( String args[ ] )
15hich ofthe following are valid declarations ofthe standard main() method?
- Astatic void main( String args[ ] ) { }
- Bpublic static int main( String args[ ] ) { }
- Cpublic static void main ( String args) { }
- Dfinal static public void main ( String[ ] arguments ) { }
- Epublic static void main ( String[ ] args) { }
16Which ofthese statements concerning the use ofmodifiers are true?
- AWhich ofthese statements concerning the use ofmodifiers are true?
- BYou cannot specify visibility oflocal variables.
- CLocal variable always have default accessibility.
- DLocal variables can be declared as private.
- ELocal variables can only be declared as public.
17Consider the following directory structure shown in Image 1 that displays available
folders and classes and the code given below.
class StockQuote{
Stock stock;
public StockQuote( Stock s) {
}p
ublic double computePrice( ) {
return Helper. getPricer( stock) . price( ) ;
}
}A
ssuming that the code uses valid method calls, what statements must be added to the
above class?- Aimport com. enthu. *;
- Bimport com. *. *;
- Cimport *. *. *;
- Dimport com. *;
- Eimport com. enthu. rad. *;
- Fimport all;
18Which line(s) in the following code will cause a compilation error?
static import j ava. lang. System. *; //1
class $$ //2
{
static public void main( String. . . _$_) //3
{
String _ = " " ; //4
for( int $=0; ++$ < _$_. length; ) //5
_
+= _$_[ $] ; //6
out. println( _) ; //7
}
}- A1
- B2
- C3
- D4
- E5
- F6
19The following is a valid member variable declaration:
private static final transient int i = 20;- ATrue
- BFalse
20Given the following class, which ofthese are valid ways ofreferring to the class from
outside ofthe package com.enthu?
package com. enthu;
public class Base{
// . . . .
// lot of code. . .
}- ABase
- BBy importing the package com. * and referring to the class as enthu. Base
- Cimporting com. * is illegal.
- DBy importing com. enthu. * and referring to the class as Base.
- EBy referring to the class as com. enthu. Base.
Informationen
- Beschreibung
- OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Quiz am 05-Objectives-Wise-Java-Basics, erstellt von Wong Fei Hung am 01/08/2017.
- Autor
- Wong Fei Hung
- Sprache
- Português
- Aufrufe
- 0
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz