Java Junior

59 Questions | Total Attempts: 5686

SettingsSettingsSettings
Java Quizzes & Trivia

It is created for Beginners in Java. This is to test the knowledge of any Java Developer wannabe.


Questions and Answers
  • 1. 
    If none of the private/protected/public is specified for a member, that member ...
    • A. 

      Is accessible publicly

    • B. 

      Is only accessible by other classes of the same package

    • C. 

      Is only accessible from within the class

    • D. 

      Is accessible by the class and its subclasses

  • 2. 
    Which one is not correct?
    • A. 

      A class needs to be instantiated as an object before being used

    • B. 

      An objects exists in memory in run time

    • C. 

      Class and object are just different names for the same thing

    • D. 

      An object is a variable, where its type is the class used to declare the variable

  • 3. 
    Which is not a part of defining an object?
    • A. 

      Description

    • B. 

      Methods

    • C. 

      Associations with other objects

    • D. 

      Name

  • 4. 
    Class B inherits from Class A, what cannot be said:
    • A. 

      B is a sub-class of A

    • B. 

      A is a super-class of B

    • C. 

      B has access to private members of A

    • D. 

      B has access to protected members of A

  • 5. 
    What is a member of a class
    • A. 

      An attribute

    • B. 

      A method

    • C. 

      Attribute or method

    • D. 

      A sub-class

  • 6. 
    A class is...
    • A. 

      An object

    • B. 

      An executable piece of code

    • C. 

      An abstract definition of an object

    • D. 

      A varibale

  • 7. 
    Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?
    • A. 

      Javax.swing

    • B. 

      Javax.gui

    • C. 

      Java.awt

    • D. 

      Java.swing

  • 8. 
    Which one needs a web page to run
    • A. 

      A Java Application

    • B. 

      A Java Stand-Alone Application

    • C. 

      A Java Applet

    • D. 

      A Java Class

  • 9. 
    How to define a JButton with the caption test?
    • A. 

      JButton aButton('test');

    • B. 

      JButton aButton=new JButton("test");

    • C. 

      JButton aButton=new JButton('test');

    • D. 

      JButton("test") aButton;

  • 10. 
    The last value in an array called ar can be found at index:
    • A. 

      0

    • B. 

      1

    • C. 

      Ar.length

    • D. 

      Ar.length - 1

  • 11. 
    What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));
    • A. 

      6

    • B. 

      2+4

    • C. 

      1+3

    • D. 

      4

  • 12. 
    What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};
    • A. 

      For (int i =0; i < 3; i++) System.out.println( nums[i]);

    • B. 

      For (i = 1; i

    • C. 

      For (i = 0; i

    • D. 

      For (i = 1; i < 3; i++) System.out.println(nums[i]);

  • 13. 
    What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);
    • A. 

      Ab

    • B. 

      Ac

    • C. 

      Ace

    • D. 

      Bd

  • 14. 
    If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
    • A. 

      0

    • B. 

      5

    • C. 

      6

    • D. 

      7

  • 15. 
    The following prototype shows that a Cylinder subclass is derived from a superclass called Circle
    • A. 

      Class Circle extends Cylinder

    • B. 

      Class Cylinder derived Circle

    • C. 

      Class Cylinder extends Circle

    • D. 

      Class Circle derived Cylinder

  • 16. 
    With inheritance, a derived subclass object can directly access any
    • A. 

      Public or private superclass member

    • B. 

      Private superclass member

    • C. 

      Public superclass member (and protected subclass members if it's in the same package)

    • D. 

      Protected, public or private superclass member

  • 17. 
    What is the role of the constructor? 
    • A. 

      Create an instance of a class (an object)

    • B. 

      Create names for methods

    • C. 

      To create some type of change in the state of an object

  • 18. 
    A class cannot be declared:
    • A. 

      Static

    • B. 

      Private

    • C. 

      Protected

  • 19. 
    Following code will result in: int num = 6.7;
    • A. 

      Compilation error

    • B. 

      Runtime error

    • C. 

      Num being 6.7

    • D. 

      Num being 6

  • 20. 
    Following code will result in: int a1 = 5; double a2 = (float)a1;
    • A. 

      Compilation error

    • B. 

      Runtime error

    • C. 

      No errors

    • D. 

      Runtime Exception

  • 21. 
    Following code will result in: int num = 8/0;
    • A. 

      Compilation error: Divisions must be in a try block

    • B. 

      Compilation error: DivideByZeroException

    • C. 

      Runtime Exception

    • D. 

      No Error: a is NaN

  • 22. 
    Following code will result in: float num = 5/0;
    • A. 

      Compilation error: Divisions must be in a try block

    • B. 

      Compilation error: DivideByZeroException

    • C. 

      Runtime Exception

    • D. 

      No Error: a is NaN

  • 23. 
    A class can be transient
    • A. 

      True

    • B. 

      False

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

      Compilation error

    • B. 

      Runtime Error

    • C. 

      Runtime Exception

    • D. 

      Output of x is 1

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

      Compile error

    • B. 

      Runtime Exception

    • C. 

      No error

    • D. 

      No Output

Back to Top Back to top