Question1: Which three statements are true about the structure of a Java class? (Choose three.)

A. A public class must have a main method.
B. A class can have only one private constructors.
C. A method can have the same name as a field.
D. A class can have overloaded static methods.
E. The methods are mandatory components of a class.
F. The fields need not be initialized before use.

Answer: A,C, E

Question2: Which three statements describe the object-oriented features of the Java language? (Choose three.)

A. Objects cannot be reused.
B. A subclass must override the methods from a superclass.
C. Objects can share behaviors with other objects.
D. A package must contain a main class.
E. Object is the root class of all other objects.
F. A main method must be declared in every class.

Answer: B,C,E

Question3: Which statement is true about the switch statement?

A. It must contain the default section.
B. The break statement, at the end of each case block, is optional.
C. Its case label literals can be changed at runtime.
D. Its expression must evaluate to a collection of values.

Answer: B

Question4: Given the below code . Which of the below two statements are correct?

ArrayList<Cycle> myList = new ArrayList<>();
myList.add(new MotorCycle());

A. MotorCycle is an interface that implements the Cycle class.
B. Cycle is an interface that is implemented by the MotorCycle class.
C. Cycle is an abstract superclass of MotorCycle.
D. Cycle and MotorCycle both extend the Transportation superclass.
E. Cycle and MotorCycle both implement the Transportation interface.
F. MotorCycle is a superclass of Cycle

Answer: BC

Question5: Which two statements are true? (Choose two.)

A. Error class is unextendable.
B. Error class is extendable.
C. Error is a RuntimeException.
D. Error is an Exception.
E. Error is a Throwable.

Answer: BC

Question6: Given the below code:

public class Person {

	String name;
	int age;
	public Person(int age, String name) {
		this.name = name;
		this.age=age;
	}
	public String getName() {
		return name;
	}
	public int getAge() {
		return age;
	}
	
}
public class Test {

	public static void main(String[] args) {
		List<Person> personsList = Arrays.asList(new Person(40, "Vijay"),new Person(10, "Arjun"),new  Person(35, "Jay"),new Person(60, "Raju"));
         //Line N1
		
	}
	
	public static void checkAge(List<Person> personsList, Predicate<Person> predicate) {
		for(Person person: personsList) {
			if(predicate.test(person)) {
				System.out.println(person.name + " ");
			}
		}
	}
}

Which of the below code is correct to insert at Line N1

A.checkAge(personsList, ()-> p.getAge()>30);
B.checkAge(personsList, Person p-> p.getAge()>30 );
C.checkAge(personsList, p-> p.getAge()>30);
D.checkAge(personsList, (Person p)->p.getAge()>30;} );

Answer: C

Explanation: The below two predicates are valid

  • checkAge(personsList, p-> p.getAge()>30);
  • checkAge(personsList, (Person p)->{return p.getAge()>30;} );

Below is the working code for above program:

public class Test {

	public static void main(String[] args) {
		List<Person> personsList = Arrays.asList(new Person(40, "Vijay"),new Person(10, "Arjun"),new Person(35, "Jay"),new Person(60, "Raju"));
		checkAge(personsList, p-> p.getAge()>30);
		checkAge(personsList, (Person p)->{return p.getAge()>30;} );
	}
	
	public static void checkAge(List<Person> personsList, Predicate<Person> predicate) {
		for(Person person: personsList) {
			if(predicate.test(person)) {
				System.out.println(person.name + " ");
			}
		}
	}
}

Question 7 – What is the result of the below program:

                int aVar = 9;
		if(aVar++<10) {
			System.out.println(aVar+"Hellow universe");
		}else {
			System.out.println(aVar+"Hellow world");
		}

A. Compilation fails.
B. 10 Hello Universe!
C. 10 Hello World!
D. 9 Hello World!

Answer: B

Leave a Reply

Your email address will not be published. Required fields are marked *