Quiz

Question 1

What is the output of the following Java program? Please assume all classes are in the same package.

class A {
    public String[] getSdlc() {
        return sdlc;
    }

    String sdlc[] = {
            "requirement analysis",
            "design",
            "development",
            "testing",
            "implementation",
            "maintenance"
    };
}
class B extends A {
    public String[] getSdlc() {
        return sdlc;
    }

    private String sdlc[] = {
            "r","d","d","t","i","m"
    };
}
class C extends B {
    public String[] getSdlc() {
        return sdlc;
    }

    String sdlc[] = {
             "s","d","l","c"
    };
}
public class Main {
    public static void main(String args[]) {
        B obj = new C();
        for (int i = 0; i < obj.getSdlc().length;
             i++) {
            System.out.print(obj.getSdlc()[i] + "");
        }
    }
}
  • [ ] requirement analysis design development testing implementation maintenance

  • [x] sdlc

  • [ ] Compile time error

  • [ ] Runtime error

  • [ ] rddtim

Question 2

What is the extension of Java source code files?

  • [ ] .jar

  • [x] .java

  • [ ] .class

  • [ ] .jv

Question 3

What is the output of the following Java program?

public class Jump_statments {
    public static void main(String args[]) {
        int x = 2;
        int y = 0;
        for (; y < 10; ++y) {
            if (y % x == 0)
                continue;
            else if (y == 8)
                break;
            else

                System.out.print(y + " ");
        }
    }
}
  • [ ] 1 2 3 4 5 6 7 8 9

  • [ ] 2 4 6 8

  • [x] 1 3 5 7 9

  • [ ] 1 3 5 7

Question 4

A class declares three methods with the same name as shown. Is this a valid example of method overloading? Assume that Fuel is a class defined in the same package.

public class FireStarter {

    public void ignite(double oxygenAmount) {
        // ignite default fuel with the given O2
    }

    public void ignite(Fuel fuel, int amount) {
        // ignite the given amount of the fuel with the default amount of oxygen.
    }

    public void ignite(Fuel fuel, int amount, double oxygenAmount) {
        // ignite the given amount of the fuel with the given O2
    }
}
  • [x] True

  • [ ] False

Question 5

What is the output of the following program? Assume that each class is correctly declared in its own file and that the main method of Chemistry is the JVM entry point. Please assume all classes are in the same package.

public class Element {
    public String appearance() {
        return "OVERRIDE THIS METHOD";
    }
}
public class Iodine extends Element {
    @Override public String appearance() {
        return "lustrous, purple-black non- metallic solid";
    }
}
public class Chemistry {
    public static void main(String[] args) {
        Element e = new Iodine();
        System.out.println(e.appearance());
    }
}
  • [ ] The program will not compile because Iodine is not an Element.

  • [ ] OVERRIDE THIS METHOD lustrous, purple-black non-metallic solid

  • [ ] OVERRIDE THIS METHOD

  • [x] lustrous, purple-black non-metallic solid

Question 6

Given these code snippets:

public abstract class Mineral {
    // define abstract methods for origin, hardness and appearance.
}
public class Diamond extends Mineral {
    // implement origin, hardness and appearance methods.
}

Is the following assignment valid?

Diamond d = new Mineral();
  • [ ] YES

  • [x] NO

Question 7

What is Polymorphism In object-oriented programing?

  • [ ] A process that binds together the data and functions that manipulate the data and that keeps both safe from outside interference and misuse.

  • [x] Refers to the ability of a variable, function or object to take on multiple forms

  • [ ] An ability by which one class acquires the properties and behaviors of another class

  • [ ] Process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.

Question 8

______________ can be declared anywhere within the class definition, but by convention, they are declared near the top of the class definition.

  • [ ] Temporary variable

  • [ ] Local variable

  • [ ] None of the mentioned

  • [x] Class variable

Question 9

Which keyword(s) can be part of a class declaration? (check all that are correct)

  • [ ] switch

  • [x] class

  • [x] extends

  • [x] implements

  • [ ] extend

Question 10

In Java, what is the difference between the String Class and the StringBuffer Class?

  • [ ] A StringBuffer is immutable, if you try to alter its value, another object gets created. A String is mutable so it can change its value.

  • [ ] No difference, the two classes are equivalent.

  • [ ] StringBuffer is the parent/super case of String.

  • [x] A String is immutable, if you try to alter its value, another object gets created. A StringBuffer is mutable so it can change its value.

Question 11

What is Truncation for numeric variables in Java?

  • [x] Floating-point value assigned to an integer type

  • [ ] Integer value assigned to floating type

  • [ ] Floating-point value assigned to an Floating type

  • [ ] None of the Mentioned

Question 12

What is the return type of Constructors?...

  • [ ] int

  • [x] No explicit return type

  • [ ] float

  • [ ] void

Question 13

Which of the following best describes the meaning of static?

  • [x] The static keyword can be applied to class members. This implies that the class members (static ones) belong to the class, not to instances of the class.

  • [ ] The static keyword, when applied to fields, means that the field can only be accessed through instances of the class.

  • [ ] When applied to a class, the static keyword implies that instances of the class are immutable.

  • [ ] The static keyword can be applied to local variables. This implies that their values persist between calls to the method that declares the variable.

Question 14

What is Autoboxing?

  • [ ] when an object of a wrapper class is automatically converted to its matching primitive value

  • [ ] A mechanism of Abstraction

  • [x] when a primitive value is automatically converted to its matching wrapper class object

  • [ ] A mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit

Question 15

What data type would you use to store the names of students?

  • [ ] int

  • [ ] boolean

  • [ ] char

  • [x] String

Question 16

What is Inheritance in Object-Oriented Programming?

  • [ ] A process that binds together the data and functions that manipulate the data and that keeps both safe from outside interference and misuse.

  • [ ] Refers to the ability of a variable, function or object to take on multiple forms

  • [ ] Process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.

  • [x] An ability by which one class acquires the properties and behaviors of another class

Question 17

Which of these is an invalid Array declaration?

  • [x] int[] arr = new int[];

  • [ ] int[] arr = new int[5];

  • [ ] None of the mentioned

  • [ ] int[] arr; arr = new int[5];

Question 18

The fields/variables in an interface are implicitly specified as -

  • [ ] static only

  • [ ] final only

  • [x] static and final

  • [ ] Integer

Question 19

What is the process of defining more than one method in a class differentiated by method signature?

  • [ ] Method Overwriting

  • [ ] Method Overlapping

  • [ ] Method Overriding

  • [x] Method Overloading

Question 20

How many copies of static (class) variables and instance variables are created when 10 objects are created of a class?

  • [ ] 1,1

  • [ ] 10, 10

  • [ ] 10,1

  • [x] 1, 10

Question 21

Which of these statements is incorrect?

  • [x] Interfaces can be instantiated

  • [ ] Interfaces cannot have constructors.

  • [ ] Abstrac classes can have constructors.

  • [ ] Abstract classes may or may not have abstract methods.

Question 22

What is the output of the following Java program? Please assume all classes are in the same package.

class A {

    void ETL() {
        String E = "mySQL";
        String T = "Sqoop";
        String L = "hdfs";
        System.out.println(E + T + L);
    };

    void ETL(String ETL) {
        System.out.println(ETL.toUpperCase());
    }
    void ETL(String E, String T, String L) {
        System.out.println(E + T + L);
    }
}

public class Main {

    public static void main(String args[]) {
        String E = "extraction1";
        String T = "transformation2";
        String L = "loading3";

        A obj = new A();
        obj.ETL(E + T + L);
    }
}
  • [ ] mySQLSqoophdfs

  • [ ] extraction1transformation2loading3

  • [x] EXTRACTION1TRANSFORMATION2LOADING3

  • [ ] EXTRACTION1 TRANSFORMATION2 LOADING3

Question 23

A method declaration has (check all that are correct):

  • [x] A name

  • [ ] At least one parameter

  • [x] A return-type, or void if no value is returned.

  • [x] An optional access specifier which, if not present, defaults to package access.

  • [x] Parentheses () - with or without a parameter list.

Question 24

Which of the below is an invalid identifier with the main() method?

  • [x] private

  • [ ] static

  • [ ] final

  • [ ] public

Question 25

What is the output of the following Java program? Please assume all classes are in the same package.

class A {
    String E = "extraction ";
    String T = "transformation ";
    String L = "loading ";

    final void ETL() {
        System.out.println(L + T + E);
    };
}

class B extends A {
    void ETL() {
        System.out.println(E + T + L);
    }
}

public class Main {
    public static void main(String args[]) {
        A obj = new B();
        obj.ETL();
    }
}
  • [ ] None of the mentioned

  • [ ] extraction transformation loading

  • [x] Compile time error

  • [ ] loading transformation extraction

  • [ ] Runtime error

Question 26

If a class of a Java program has a plural number of methods, and all of them have the same name but different parameters (with a change in type or number of arguments), then it is known as method overloading.

  • [x] True

  • [ ] False

Question 27

Which of the following modifier means a particular variable cannot be accessed from other class even within the same package?

  • [ ] default

  • [ ] protected

  • [ ] public

  • [x] private

Question 28

Variables, methods, and constructors, which are declared protected in a superclass can be accessed only by the subclasses in other packages or any class within the package of the protected members' class.

  • [x] True

  • [ ] False

Question 29

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

  • [ ] for

  • [ ] None of the above

  • [x] do-while

  • [ ] while

Question 30

Which of the following is a valid declaration of an object of class Box?

  • [ ] Box new obj;

  • [x] Box obj = new Box();

  • [ ] obj = new Box();

  • [ ] Box obj = new Box;

Last updated