OOP-j Class Test

58 Questions | Attempts: 206
Share

SettingsSettingsSettings
Object Oriented Programming Quizzes & Trivia

This is no negative marking.
Attempt it only once.


Questions and Answers
  • 1. 

    What is the size of a Char?

    • A.

      4 bits

    • B.

      7 bits

    • C.

      8 bits

    • D.

      16 bits

    Correct Answer
    D. 16 bits
  • 2. 

     A class cannot be declared

    • A.

      Static

    • B.

      Private

    • C.

      Final

    • D.

      Public

    Correct Answer
    B. Private
  • 3. 

    Following code will result in: int a = 3.5;

    • A.

      Compilation error

    • B.

      Runtime error

    Correct Answer
    A. Compilation error
  • 4. 

     Following code will result in: int a = 9/0;

    • A.

      Compilation error: Divisions must be in a try block.

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
  • 5. 

    Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); }}

    • A.

      Compilation error

    • B.

      Runtime Error

    Correct Answer
    A. Compilation error
  • 6. 

    Following code will result in: class A { public static void main(String [] args) {B a = new A(); }} class B extends A {}

    • A.

      Compile error

    • B.

      No error

    Correct Answer
    A. Compile error
  • 7. 

    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

    • A.

      Runtime Exception

    • B.

      No errors

    Correct Answer
    B. No errors
  • 8. 

    Methods that are marked protected can be called in any subclass of that class.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 9. 

    A static class can have non-static methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 10. 

    What is old name of "Java"

    • A.

      OAK

    • B.

      OCK

    Correct Answer
    A. OAK
  • 11. 

    What is the use of "this " keyword

    • A.

      To refer current variable

    • B.

      To refer current object

    • C.

      To refer current class

    • D.

      To refer current method

    Correct Answer
    B. To refer current object
  • 12. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
  • 13. 

    If class A implements an interface does it need to implement all methods of that interface?

    • A.

      Yes, always

    • B.

      No, not when A is abstract

    Correct Answer
    B. No, not when A is abstract
  • 14. 

    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

    • A.

      True

    • B.

      FALSE

    Correct Answer
    B. FALSE
  • 15. 

    Inner classes can be defined within methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 16. 

    The default statement of a switch is always executed

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 17. 

    What is Java (in regard to Computer Science) ?

    • A.

       A type of coffee

    • B.

      AN OBJECT-ORIENTED PROGRAMMING LANGUAGE

    Correct Answer
    B. AN OBJECT-ORIENTED PROGRAMMING LANGUAGE
  • 18. 

    WHAT IS USE OF SUPER KEYWORD

    • A.

      TO CALL SUPER CLASS CONSTRUCTOR

    • B.

      TO CALL ANY CLASS CONSTRUCTOR

    Correct Answer
    A. TO CALL SUPER CLASS CONSTRUCTOR
  • 19. 

    Java runs on _______.

    • A.

       Windows

    • B.

      All of the Above

    • C.

       Unix/Linux

    Correct Answer
    B. All of the Above
  • 20. 

    What is the main function of any variable ?

    • A.

       To add numbers together

    • B.

       To keep track of data in the memory of the computer

    Correct Answer
    B.  To keep track of data in the memory of the computer
  • 21. 

    What is the proper way to declare a variable ?

    • A.

      VariableName variableType;

    • B.

      VariableType variableName;

    Correct Answer
    B. VariableType variableName;
  • 22. 

     Booleans are _______.

    • A.

       True or False

    • B.

       Single characters

    Correct Answer
    A.  True or False
  • 23. 

    The following statements make “index and length” be what number ?int a[]=new int[20];

    • A.

       19,20

    • B.

      20,20

    Correct Answer
    A.  19,20
  • 24. 

    What is an assignment statement ?

    • A.

      Assigning a name to a variable

    • B.

      Assigning a value to a variable

    Correct Answer
    B. Assigning a value to a variable
  • 25. 

    What is use of final keyword 

    • A.

      To make invisible variable

    • B.

      To make a constant variable

    • C.

      To make a visible variable

    Correct Answer
    B. To make a constant variable
  • 26. 

     If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

    • A.

      &&

    • B.

      !!

    Correct Answer
    A. &&
  • 27. 

    Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

    • A.

       if ((x < 3) || (y > = 4))

    • B.

       if ((x > 3) || (y < = 4))

    Correct Answer
    A.  if ((x < 3) || (y > = 4))
  • 28. 

     What is a loop ?

    • A.

       A new type of Applet

    • B.

       A segment of code to be run a specified amount of times

    Correct Answer
    B.  A segment of code to be run a specified amount of times
  • 29. 

    What is essential in making sure that your loop is not infinite ?

    • A.

      That there is a Boolean statement somewhere in your code

    • B.

      That your Boolean statement will at some point be false

    Correct Answer
    B. That your Boolean statement will at some point be false
  • 30. 

    Which is NOT a section of all types of loops ?

    • A.

       Test statement

    • B.

       The word "while"

    Correct Answer
    B.  The word "while"
  • 31. 

    In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

    • A.

       Loop Body

    • B.

       Initialization

    Correct Answer
    A.  Loop Body
  • 32. 

    What is a function in terms of Computer Science ?

    • A.

       A group of code lines that performs a specific task

    • B.

       Something that contains an ‘init’

    Correct Answer
    A.  A group of code lines that performs a specific task
  • 33. 

    What does JVM stands for ?

    • A.

      Java Virtual Machine

    • B.

      Java Virtue Machine

    • C.

      Java Visual Machine

    Correct Answer
    A. Java Virtual Machine
  • 34. 

    Which is right way to creating an array of integer in java?

    • A.

      Int javaArray = new int[10];

    • B.

      Int avaArray new = myArray[ ];

    • C.

      Int[] javaArray = new int[10];

    • D.

      None

    Correct Answer
    C. Int[] javaArray = new int[10];
  • 35. 

    Which keyword is used to inherit class?

    • A.

      Inherit

    • B.

      Extends

    • C.

      Inheritance

    • D.

      Extend

    Correct Answer
    B. Extends
  • 36. 

    Which of the java classes that cannot be subclassed?

    • A.

      Abstract class

    • B.

      Public class

    • C.

      Final class

    • D.

      None of above

    Correct Answer
    C. Final class
  • 37. 

    Can we declare abstract static method?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
  • 38. 

    Which type of inheritance is not supported by java?

    • A.

      Single

    • B.

      Multiple

    • C.

      Multilevel

    • D.

      Hirarchical

    Correct Answer
    B. Multiple
  • 39. 

    Java final methods cannot be overridden but overloaded?

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 40. 

    Given the below class definitions   class Base { void display () { System.out.println("Base"); } } class Derived extends Base { void display () { System.out.println("Derived"); } } and objects Base b = new Base(); Derived d = new Derived(); Base bd = new Derived(); then the print statements System.out.print(b.display() + " "); System.out.print(d.display() + " "); System.out.print(bd.display() + " "); System.out.println(); will display:

    • A.

      Base Base Derived

    • B.

      Base Derived Derived

    • C.

      Base Derived Base

    • D.

      Derived Derived Derived

    Correct Answer
    B. Base Derived Derived
  • 41. 

    Which of the following are primitive types?

    • A.

      Byte

    • B.

      String

    • C.

      Integer

    • D.

      Float

    Correct Answer
    A. Byte
  • 42. 

    Which of the following statements accurately describe the use of access modifiers(private,public,protected) within a class definition?

    • A.

      They can be applied to both data & methods

    • B.

      They must precede a class's data variables or methods

    • C.

      They can follow a class's data variables or methods

    • D.

      They can appear in any order

    • E.

      They must be applied to data variables first and then to methods

    Correct Answer(s)
    A. They can be applied to both data & methods
    B. They must precede a class's data variables or methods
    D. They can appear in any order
  • 43. 

    Which of the following statements correctly describes the relation between an object and the instance variable it stores?

    • A.

      Each new object has its own distinctive set of instance variables

    • B.

      Each object has a copy of the instance variables of its class

    • C.

      The instance variable of each object are seperate from the variables of other objects

    • D.

      The instance variables of each object are stored together with the variables of other objects

    Correct Answer(s)
    A. Each new object has its own distinctive set of instance variables
    B. Each object has a copy of the instance variables of its class
    C. The instance variable of each object are seperate from the variables of other objects
  • 44. 

    What is the size of int in java 

    • A.

      2 bytes

    • B.

      4 bytes

    • C.

      6 bytes

    • D.

      Depends on platform

    Correct Answer
    B. 4 bytes
  • 45. 

    Which of the following is true about class defination in a file 

    • A.

      In a single file any number of class can be defined

    • B.

      There can be only one public class in a single java file

    • C.

      Name of public file and class name should match

    • D.

      All of above

    Correct Answer
    D. All of above
  • 46. 

    What is the output of following code int x[]={1,2,3,4}; Sytem.out.println(" Index at 4 is "+x[4]);

    • A.

      IndexOutOfBoundException

    • B.

      4

    • C.

      NullPointerException

    • D.

      3

    Correct Answer
    A. IndexOutOfBoundException
  • 47. 

    Given the below code. What is the result?    class Test    {        public static void main(String args[]) {                 String str = "null";                 if (str == null) {                         System.out.print("1");                 } else if (str.length() == 0) {                         System.out.print("2");                 } else {                         System.out.print("3");                 }         }   }

    • A.

      Compilation fails.

    • B.

      "1" is printed

    • C.

      2" is printed.

    • D.

      "3" is printed.

    Correct Answer
    D. "3" is printed.
  • 48. 

    In the below code which can directly access and change the value of the variable id? package com.cisco.mycompany;   public class Company  {     private int id = 100; }

    • A.

      Only the Company class

    • B.

      Any class

    • C.

      Any class in com.cisco.mycompany package

    • D.

      Any class that extends Company

    Correct Answer
    A. Only the Company class
  • 49. 

    Given the code. What is the result after the class TryMe execution? class A {     public void doA() {         B b = new B();         b.dobB();         System.out.print("doA");     } }   class B {     public void dobB() {         C c = new C();         c.doC();         System.out.print("doB");     } }   class C {     public void doC() {         if (true)             throw new NullPointerException();         System.out.print("doC");     } }   public class TryMe {       public static void main(String args[]) {         try {             A a = new A();             a.doA();         } catch (Exception ex) {             System.out.print("error");         }     } }

    • A.

      "doCdoBdoA" is printed

    • B.

      "doAdoBdoC" is printed

    • C.

      "doBdoAerror" is printed

    • D.

      "error" is printed

    Correct Answer
    D. "error" is printed
  • 50. 

    Given the code. What is the result if NullPointerException occurs at line 2? 1.      try { 2.          //some code goes here 3.      } 4.      catch (NullPointerException ne) { 5.          System.out.print("1 "); 6.      } 7.      catch (RuntimeException re) { 8.          System.out.print("2 "); 9.      } 10.     finally { 11.         System.out.print("3"); 12.     }

    • A.

      1

    • B.

      3

    • C.

      1 3

    • D.

      2 3

    Correct Answer
    C. 1 3

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Sep 15, 2014
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 12, 2014
    Quiz Created by
    Mahesh_seelak

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.