Quiz : OCA Java SE 8 methods and encapsulation practice

java 8 methods and encapsulation oca
Total Question : 5

In the exam, you must answer questions about methods and encapsulation. This Java quiz will help you get the correct answers by covering the following:

  • Defining the scope of variables.
  • Explaining an object’s life cycle.
  • Creating methods with primitive and object arguments and return values.
  • Creating overloaded methods and constructors.
  • Reading and writing to object fields.
  • Calling methods on objects.
  • Applying encapsulation principles to a class.
  1. Which option defines a well-encapsulated class?

     

  2. Examine the following code and select the correct option(s):

    public class Person {
        public int height;
        public void setHeight(int newHeight) {
            if (newHeight <= 300)
                height = newHeight;
        }
    }
  3. Select the incorrect options

  4. Given the following code,

    class Course {
        void enroll(long duration) {
            System.out.println("long");
        }
        void enroll(int duration) {
            System.out.println("int");
        }
        void enroll(String s) {
            System.out.println("String");
        }    void enroll(Object o) {
            System.out.println("Object");
        }
    }

    what is the output of the following code?

    class EJavaGuru {
        public static void main(String args[]) {
                Course course = new Course();
                char c = 10;
                course.enroll(c);
                course.enroll("Object");
        }
    }
  5. Given  the  following  signature  of  method eJava,  choose  the  options  that  cor-rectly overload this method:


Retated posts