Core Java Questions: Quiz! Exam

30 Questions | Total Attempts: 2678

SettingsSettingsSettings
Core Java Questions: Quiz! Exam - Quiz

.


Questions and Answers
  • 1. 
    Consider the following listed items: A. Employee() { } B. public Employee() { } C. private Employee() { } Consider the following statements: I.   no-argument constructor, that does not allow instantiation from within the package II.  no-argument constructor, that does not allow instantiation from outside the package III. no-argument constructor Which of the following option gives the exact matches of above listed items and statements?   Consider the following listed items: A. Employee() { } B. public Employee() { } C. private Employee() { } Consider the following statements: I.   no-argument constructor, that does not allow instantiation from within the package II.  no-argument constructor, that does not allow instantiation from outside the package III. no-argument constructor Which of the following option gives the exact matches of above listed items and statements?{  
    • A. 

      A-I, B-II, C-III

    • B. 

      A-III, B-I, C-II

    • C. 

      A-II, B-III, C-I

    • D. 

      A-II, B-I, C-III

  • 2. 
    Which of the following statement is true regarding constructors?
    • A. 

      Abstract classes cannot have constructors

    • B. 

      Default Constructors are Optional for all classes

    • C. 

      can be overloaded across inherited classes

    • D. 

      Default Constructors are optional only for the classes that does not have constructors

  • 3. 
    Which of the following keyword is used to define user-defined annotation type?
    • A. 

      Interface

    • B. 

      Annotate

    • C. 

      Annotation

    • D. 

      Meta

    • E. 

      Metadata

  • 4. 
    Which of the following options give the annotation types that are predefined by the language specification itself? 1) Deprecated 2) Override 3)SuppressWarnings 4) Documented 5) Target
    • A. 

      2,3,4

    • B. 

      1,2,3

    • C. 

      3,4,5

    • D. 

      1,2,5

    • E. 

      1,3,4

  • 5. 
    Which of the following option gives the super type of all Annotation types?
    • A. 

      Java.lang.Annotation

    • B. 

      Java.lang.annotation.Annotation

    • C. 

      Java.annotation.Annotation

    • D. 

      There is no super type for an Annotation type. An Annotation type is just an interface definition

  • 6. 
    Which of the following is true about Annotations?
    • A. 

      An annotation is a special kind of modifier

    • B. 

      An annotation can be declared at public, private, protected and package access levels

    • C. 

      Annotation methods allow wrapper types as its return types, as an alternative to its equivalent primitive types

    • D. 

      Annotations can replace interfaces in Java

  • 7. 
    Consider the following Statements: A: WeakHashMap is synchronized. B: All Set implementation Rejects Duplicates but is ordered. Which of the following option is true regarding the above statements?
    • A. 

      Statement B is True and Statement A is false

    • B. 

      Both the Statements A and B are false

    • C. 

      Statement A is True and Statement B is false

    • D. 

      Both the Statements A and B are true

  • 8. 
    Consider the following list of items in Column A and column B Column A 1) Vector 2) HashSet 3) TreeSet 4) ArrayList Column B A) It is not ordered or sorted B) It compares and stores the data in a sorting order C) Permits all elements including NULL. D) It tries to optimize storage management by maintaining a capacity and a capacity Increment. Which of the following option gives the valid match between the Items in Column A and Statements in Column B?  
    • A. 

      2-A, 3-B, 4-C, 1-D

    • B. 

      1-A, 2-B, 3-C, 4-D

    • C. 

      1-A, 3-B, 4-C, 2-D

    • D. 

      2-A, 4-B, 3-C, 1-D

  • 9. 
    Which of the following statements give the advantages of using a Generic Collection? 1) Thread Safety 2) Type Safety 3) JVM Safety 4) Automatic Type Casting 5) Quicker Garbage Collection
    • A. 

      2,3

    • B. 

      1,2

    • C. 

      4,5

    • D. 

      2,4

    • E. 

      1,5

  • 10. 
    Consider the following scenario: A java application needs to load all the rows as objects from a database table and keep it in the memory, with the following features: * An object should be fetched based on the primary key * When a new object is added to the memory, it should get inserted to the database table * When an existing object is removed, the corresponding row should be removed from the database * When any changes are made to the object the changes have to be updated to the database. Which of the following collection implementation would be suitable for the above scenario?  
    • A. 

      Linked list

    • B. 

      Hash set

    • C. 

      Array list

    • D. 

      Hash map

  • 11. 
    Two Client Systems A and B are connected to a Server. Client A keeps sending some messages asynchronously to Client B through the Server. The server keeps track of all the messages coming from Client A and dispatches it in the same sequences how it is received from Client A. The messages sent by Client A is delivered to Client B after a short time delay. Which of the following collection implementation the server should use to handle the messages sent by Client A?
    • A. 

      Hash map

    • B. 

      Hash set

    • C. 

      Queue

    • D. 

      Stack

    • E. 

      Array list

  • 12. 
    Consider the following scenario: An ArrayList is populated with the names of all the employees in a company. Now the names start with the string "AR" should only be removed from the list. Which of the following option gives the correct interface that helps to accomplish the above task?{
    • A. 

      Remover

    • B. 

      Enumerator

    • C. 

      Enumeration

    • D. 

      Iterator

    • E. 

      Comaprator

  • 13. 
    Consider the following scenario: The Employee objects are populated in an ArrayList in order to show it to the user. The User Interface is designd in such a way to display one record at a time. Appropriate buttons are provided to browse through the previous and next record. Which of the following option gives the correct interface that helps to accomplish the above task?{  
    • A. 

      Consider the following scenario: The Employee objects are populated in an ArrayList in order to show it to the user. The User Interface is designed in such a way to display one record at a time. Appropriate buttons are provided to browse through the previous and next records. Which of the following option gives the correct interface that helps to accomplish the above task?{ Consider the following scenario: The Employee objects are populated in an ArrayList in order to show it to the user. The User Interface is designed in such a way to display one record at a time. Appropriate buttons are provided to browse through the previous and next records. Which of the following option gives the correct interface that helps to accomplish the above task?{ List Iterator

    • B. 

      Enumerator

    • C. 

      Iterator

    • D. 

      Enumeration

    • E. 

      Browser

  • 14. 
    Consider the following scenario: An Online Ticket Booking application designed using Java needs to store the booked date and time. Which of the following option gives the valid class that can accomplish the above task?  
    • A. 

      Java.util.Calendar

    • B. 

      Java.util.date

    • C. 

      Java.util.dat & java.util.time

    • D. 

      Java.util.timestamp

  • 15. 
    An HR application is being developed in Java. A particular module needs to calculate the number of days between the project start date and end date for an employee, in order to arrive at the billable days. The given inputs are day, month, and year values for the project start date and end date. Which of the following option gives the valid class that can accomplish the above task?  
    • A. 

      Java.util.Calendar

    • B. 

      Java.util.Time

    • C. 

      Java.util.Date

    • D. 

      Java.util.Timestamp

  • 16. 
    Consider the following scenario: A method called getRows() in a Java module needs to return some set of objects when the method is called, but subject to the conditions below: * The objects can be duplicated * But the Objects should maintain the order * The number of fields in the object will vary for every method call   (For example: For the first call there could  be 5 fields in the returned list of objects, and for the next call there could be 3 fields and so on.) * Types of fields may also vary for every call. Which of the following Generic Collection based method Declaration is most suitable for handling the data related to the above scenario effectively?{
    • A. 

      Public List getRows();

    • B. 

      Public List getRows()

    • C. 

      Public List getRows();

    • D. 

      Public List getRows();

  • 17. 
    Consider the following code: interface Declare {  Declaration 1:  protected int a = 5;           Declaration 2:  public static final int e = 9; Declaration 3:  volatile int c = 7;            Declaration 4:  transient int d = 8;           } Which of the following option gives the declarations that results in compilation error
    • A. 

      Declaration 2,4

    • B. 

      Declaration 1,3,4

    • C. 

      ~Declaration 1,2,3

    • D. 

      ~Declaration 2,3,4

  • 18. 
    Which of the following statement is true?
    • A. 

      Has-a relationships always rely on inheritance

    • B. 

      Has-a relationships always rely on instance variables

    • C. 

      Has-a relationships always require at least two class types

    • D. 

      Has-a relationships always rely on polymorphism

  • 19. 
    Consider the following code: Line No 1:public class CallMe { Line No 2:   int i=10; Line No 3: public void view(){ Line No 4:  System.out.println(j); Line No 5: } Line No 6: class WishMe{ Line No 7:  int j=20; Line No 8:  public void view(){ Line No 9:   System.out.println(i); Line No 10:  }}} Which of the following option gives the valid output for the above code?{
    • A. 

      Compilation error at line 9

    • B. 

      10,20

    • C. 

      20,10

    • D. 

      Compilation error at 4th line

  • 20. 
    Consider the following code: Line No 1:public class Calculate { Line No 2:int i; Line No 3:void add() Line No 4:{System.out.println("Addition Method returns nothing");} Line No 5:int add() Line No 6:{System.out.println("Addition Method returns integer"); Line No 7: return i;} Line No 8:} Line No 9:public class TestCalculate { Line No 10: public static void main(String args[]) Line No 11: {Calculate c=new Calculate(); Line No 12:  c.add();   }} Which of the following option gives the valid output for the above code?{
    • A. 

      Addition returns integer

    • B. 

      Runtime error at line 12

    • C. 

      Addition method returns nothin

    • D. 

      Compilation error at line 5

  • 21. 
    Consider the following code: Line No:1. class Super { Line No:2. public float getNum() { return 3.0f; } Line No:3. } Line No:4. public class Sub extends Super { Line No:5//insert missing code here Line No:6. } Which of the following option gives the method, when replaced at line 6, causes unsuccessful compilation? {
    • A. 

      Public void getNum(double d) { }

    • B. 

      Public void getNum() { }

    • C. 

      Public float getNum() { return 4.0f; }

    • D. 

      Public double getNum(float d) { return 4.0d; }

  • 22. 
    Which of the following statement is true regarding throws declaration in Exception handling?
    • A. 

      All sub class types of exceptions that come under java.lang.RuntimeException, if not handled inside a method should be declared using throws keyword

    • B. 

      All sub class types of errors that come under java.lang.Error, if not handled inside a method should be declared using throws keyword

    • C. 

      All sub class types of java.lang.Throwable, if not handled inside a method should be declared using throws keyword

    • D. 

      All sub class types of exceptions that come under java.lang.Exception, if not handled inside a method should be declared using throws keyword

    • E. 

      None of the listed options

  • 23. 
    Which of the following statement is true regarding the throws declarations for overridden methods?
    • A. 

      The overriding method cannot declare additional exceptions which is not declared in its super class version.

    • B. 

      ~When a method in the super class is declared to throw a Checked Exception, the overriding method in the sub class should also declare the same.

    • C. 

      The overriding methods cannot declare to throw the Super Class types of those exceptions declared in the super class methods

    • D. 

      The overriding method cannot re-declare the Unchecked exceptions, that are declared by super class method.

  • 24. 
    Which of the following statements are true regarding try-catch-finally blocks? 1) Catch block is optional when a RuntimeException is thrown from the try block 2) Catch block is optional, if finally block is available, provided a Checked Exception is thrown from the try block 3) Finally block is optional, irrespective of catch block 4) Both catch block and finally block are optional, either Checked exception or unchecked exception is thrown from the try block 5) Both catch block and finally block are required, irrespective of the type of exceptions thrown from the try block{  
    • A. 

      3,4

    • B. 

      1,2

    • C. 

      2,3

    • D. 

      1,3

  • 25. 
    Which of the following are true regarding implementing user defined exception mechanisms? 1) It is not valid to derive a class from java.lang.Throwable 2) It is not valid to derive a class from java.lang.Error 3) It is valid to derive a class from java.lang.Exception 4) It is valid to derive a class from java.lang.RuntimeException 5) It is not valid to derive a class from java.io.IOException
    • A. 

      3,4

    • B. 

      3,5

    • C. 

      4,5

    • D. 

      1,2

Back to Top Back to top