GoConqr has a new look! Let us know what you think.

Quiz

05-Objectives-Wise-Java-Basics

Wong Fei Hung 20 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (20)

  1. 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] ) ;
    }
    }
    }
    1. AIt will not compile because interface XMen cannot be instantiated.
    2. BIt will print shot : 4 times, one at each line.
    3. CIt will print "shot : s", "shot : e", "shot : l", "shot : f" one by one on 4
      lines.
    4. DIt will compile but will throw an exception at runtime.
    5. ENone ofthese options is correct.
  2. 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;
    }
    }
    1. AThe program will fail to compile, since the static method main is trying to call the
      non-static method func.
    2. BThe program will fail to compile, since the non-static method func cannot access
      the static member variable ref.
    3. 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.
    4. 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.
    5. EThe program will compile and run successfully.
  3. 3Which ofthe following statements is correct?
    1. Anew, delete and goto are keywords in the Java language
    2. Btry, catch and thrown are keywords in the Java language
    3. Cstatic, unsigned and long are keywords in the Java language
    4. Dexit, class and while are keywords in the Java language
    5. Ereturn, goto and default are keywords in the Java language
  4. 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.
    1. Aimport j ava. lang. *;
    2. Bimport j ava. io. *;
    3. Cimport j ava. io. OutputStreamWriter;
    4. Dinclude j ava. io. *;
    5. Einclude j ava. lang. System;
  5. 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" ) ;
    }
    }
    }
    1. AThe program will fail to compile.
    2. BThe program will throw a NullPointerException when run with zero arguments.
    3. CThe program will print no arguments and 1 arguments when called with zero
      and one arguments.
    4. DThe program will print no arguments and 2 arguments when called with zero
      and one arguments.
    5. EThe program will print no arguments and 3 arguments when called with zero
      and one arguments.
  6. 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?
    1. Aimport static X;
    2. Bimport static com. foo. *;
    3. Cimport static com. foo. X. *;
    4. Dimport com. foo. *;
    5. Eimport com. foo. X. LOGICID;
  7. 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.
    }
    }
    }
    1. A1
    2. B2
    3. C3
    4. D4
    5. E5
  8. 8Which ofthe following keywords may occur multiple times in a Java source file?
    1. Aimport
    2. Bclass
    3. Cprivate
    4. Dpackage
    5. Epublic
  9. 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)
    1. ADeclarations (1) and (3) cannot occur in the same class definition.
    2. BDeclarations (2) and (4) cannot occur in the same class definition.
    3. CDeclarations (1) and (4) cannot occur in the same class definition.
    4. DDeclarations (2) and (3) cannot occur in the same class definition.
    5. EDeclarations (1) and (2) cannot occur in the same class definition.
  10. 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
    1. AIt will print Problem in 0
    2. BIt will throw an exception and end without printing anything.
    3. CIt will not even compile.
    4. DIt will not print anything ifthe argument is '1' instead of'one'.
    5. ENone ofthe above.

Information

Description
OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Quiz on 05-Objectives-Wise-Java-Basics, created by Wong Fei Hung on 01/08/2017.
Language
Português
Views
0
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?