OCJP Certification Sample Question Set-7

    0
    127
    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    OCJP Certification Sample Question Set-7
    OCJP Certification Sample Question Set-7

    OCJP Certification Sample Question Set-7:

    Lang Package Related:

    java.lang package is automatically imported into all programs.
    True
    False
    Ans : a
    What are the interfaces defined by java.lang?
    Ans : Cloneable, Comparable and Runnable.
    What are the constants defined by both Flaot and Double classes?
    Ans : MAX_VALUE,
    MIN_VALUE,
    NaN,
    POSITIVE_INFINITY,
    NEGATIVE_INFINITY and
    TYPE.
    What are the constants defined by Byte, Short, Integer and Long?
    Ans : MAX_VALUE,
    MIN_VALUE and
    TYPE.
    What are the constants defined by both Float and Double classes?
    Ans : MAX_RADIX,
    MIN_RADIX,
    MAX_VALUE,
    MIN_VALUE and
    TYPE.
    What is the purpose of the Runtime class?
    Ans : The purpose of the Runtime class is to provide access to the Java runtime system.
    What is the purpose of the System class?
    Ans : The purpose of the System class is to provide access to system resources.
    Which class is extended by all other classes?
    Ans : Object class is extended by all other classes.
    Which class can be used to obtain design information about an object?
    Ans : The Class class can be used to obtain information about an object’s design.
    Which method is used to calculate the absolute value of a number?
    Ans : abs( ) method.
    What are E and PI?
    Ans : E is the base of the natural logarithm and PI is the mathematical value pi.
    Which of the following classes is used to perform basic console I/O?
    System
    SecurityManager
    Math
    Runtime
    Ans : a.
    Which of the following are true?
    The Class class is the superclass of the Object class.
    The Object class is final.
    The Class class can be used to load other classes.
    The ClassLoader class can be used to load other classes.
    Ans : c and d.
    Which of the following methods are methods of the Math class?
    absolute( )
    log( )
    cosine( )
    sine( )
    Ans : b.
    Which of the following are true about the Error and Exception classes?
    Both classes extend Throwable.
    The Error class is final and the Exception class is not.
    The Exception class is final and the Error is not.
    Both classes implement Throwable.
    Ans : a.
    Which of the following are true?
    The Void class extends the Class class.
    The Float class extends the Double class.
    The System class extends the Runtime class.
    The Integer class extends the Number class.
    Ans : d.
    Which of the following will output -4.0
    System.out.println(Math.floor(-4.7));
    System.out.println(Math.round(-4.7));
    System.out.println(Math.ceil(-4.7));
    d) System.out.println(Math.Min(-4.7));
    Ans : c.
    Which of the following are valid statements
    a) public class MyCalc extends Math
    b) Math.max(s);
    c) Math.round(9.99,1);
    d) Math.mod(4,10);
    e) None of the above.
    Ans : e.
    What will happen if you attempt to compile and run the following code?
    Integer ten=new Integer(10);
    Long nine=new Long (9);
    System.out.println(ten + nine);
    int i=1;
    System.out.println(i + ten);
    19 followed by 20
    19 followed by 11
    Error: Can’t convert java lang Integer
    d) 10 followed by 1
    Ans : c.

    String Handling Related:

    Which package does define String and StringBuffer classes? 
    Ans : java.lang package.
    Which method can be used to obtain the length of the String? 
    Ans : length( ) method.
    How do you concatenate Strings? 
    Ans : By using ” + ” operator.
    Which method can be used to compare two strings for equality? 
    Ans : equals( ) method.
    Which method can be used to perform a comparison between strings that ignores case differences? 
    Ans : equalsIgnoreCase( ) method.
    What is the use of valueOf( ) method? 
    Ans : valueOf( ) method converts data from its internal format into a human-readable form.
    What are the uses of toLowerCase( ) and toUpperCase( ) methods? 
    Ans : The method toLowerCase( ) converts all the characters in a string from uppercase to lowercase. 
    The method toUpperCase( ) converts all the characters in a string from lowercase to 
    uppercase. 
    Which method can be used to find out the total allocated capacity of a StrinBuffer? 
    Ans : capacity( ) method.
    Which method can be used to set the length of the buffer within a StringBuffer object? 
    Ans : setLength( ).
    What is the difference between String and StringBuffer? 
    Ans : String objects are constants, whereas StringBuffer objects are not.
    String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings.
    What are wrapper classes? 
    Ans : Wrapper classes are classes that allow primitive types to be accessed as objects. 
    Which of the following is not a wrapper class?
    String 
    Integer 
    Boolean 
    Character
    Ans : a.
    What is the output of the following program?
    public class Question {
    public static void main(String args[]) {
    String s1 = “abc”;
    String s2 = “def”;
    String s3 = s1.concat(s2.toUpperCase( ) );
    System.out.println(s1+s2+s3);
    }
    }
    abcdefabcdef 
    abcabcDEFDEF 
    abcdefabcDEF 
    None of the above
    ANS : c.
    Which of the following methods are methods of the String class?
    delete( ) 
    append( ) 
    reverse( ) 
    replace( )
    Ans : d.
    Which of the following methods cause the String object referenced by s to be changed?
    s.concat( ) 
    s.toUpperCase( ) 
    s.replace( ) 
    s.valueOf( )
    Ans : a and b.
    String is a wrapper class?
    True 
    False
    Ans : b.
    If you run the code below, what gets printed out? 
    String s=new String(“Bicycle”); 
    int iBegin=1; 
    char iEnd=3; 
    System.out.println(s.substring(iBegin,iEnd));
    Bic 
    ic 
    icy 
    error: no method matching substring(int,char)
    Ans : b.
    Given the following declarations 
    String s1=new String(“Hello”) 
    String s2=new String(“there”); 
    String s3=new String();
    Which of the following are legal operations? 
    s3=s1 + s2; 
    s3=s1 – s2; 
    s3=s1 & s2 
    d) s3=s1 && s2 
    Ans : a.
    Which of the following statements are true? 
    The String class is implemented as a char array, elements are addressed using the stringname[] convention 
    b) Strings are a primitive type in Java that overloads the + operator for concatenation 
    c) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type 
    d) The size of a string can be retrieved using the length property.
    Ans : b.
    Don't miss out!
    Subscribe To Newsletter

    Receive top technical news, lesson ideas, travel tips and more!

    Invalid email address
    Give it a try. You can unsubscribe at any time.

    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here