Press enter to see results or esc to cancel.

Venturehack Questionnaire- Java [Set-A]

Venturehack organized by Venturehire invited all Geeks,designers,analysts- all engineering profiles to test their skills. There was a series of written and coding test to judge the skills of individuals. We will share a series of questionnaires every week to make you prepare  for the future interviews. With this series you will get every detailed answers to make you understand the concept rather than mugging up answers.

1.. Suppose a class has public visibility. In this class we define a protected method. Which of the following statements is correct?

  •  This method is only accessible from inside the class itself and from inside all subclasses.
  •  In a class, you can not declare methods with a lower visibility than the visibility of the class in which it is defined.
  • From within protected methods you do not have access to public methods.
  • This method is accessible from within the class itself and from within all classes defined in the same package as the class itself. (correct)

Description: The protected modifier specifies that the member can only be accessed within its own package and, in addition, by a subclass of its class in another package.

Class Accessibility chart:

Modifier

Class

Package

Subclass

World

public

Y

Y

Y

Y

protected

Y

Y

Y

N

no modifier

Y

Y

N

N

private

Y

N

N

N

2. Given these classes:

public class Person{
public void talk(){
System.out.print(“I am a Person”);
}
public class Student extends Person {
public void talk(){
System.out.print(“I am a Student “);
}

what is the result of this piece of code:

public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk();
}

  •  I am a Person
  •  I am a Student (correct)
  •  I am a Person I am a Student
  •  I am a Student I am a Person

Description: When type of the object is determined at run-time, it is known as dynamic binding.

3.Which three form part of correct array declarations? 1. public int a [ ] 2. static int [ ] a 3. public [ ] int a 4. private int a [3] 5. private int [3] a [ ] 6. public final int [ ] a

  1.  1, 3, 4
  2.  2, 4, 5
  3.  1, 2, 6 (correct)
  4.  2, 5, 6

Syntax: ArrayDataType ArrayName [];

4.What allows the programmer to destroy an object x in Java?

  •  x.delete().
  •  x.finalize()
  •  Runtime.getRuntime().gc()
  • Only the garbage collection system can destroy an object (correct)

Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects.

5. Which of the given below statements is incorrect regarding a static nested class?

  •  It does not have access to nonstatic members of the enclosing class.
  • One must not have a reference to an instance of the enclosing class in order to instantiate it. (correct)
  • It’s variables and methods must be static.
  • both b and c

Description: A static nested class cannot refer directly to instance variables or methods defined in its enclosing class: it can use them only through an object reference.

6.What is the default priority number of the thread in below program?

class example {

public static void main(String args[]) {

Thread t = Thread.currentThread();

System.out.println(t);

} }

  • 0
  •  4
  •  5 (correct)
  •  none of these

Description: All Java threads have a priority in the range 1-10. Priority by default is 5.

7. How can you serialize an object?

  • You have to make the class of the object implement the interface Serializable. (correct)
  •  You must call the method serializeObject() (which is inherited from class Object) on the object.
  •  You should call the static method serialize(Object obj) from class Serializer, with as argument the object to be serialized.

Read the documentation here.

8. What are the different types of statements in JDBC?

  •  statement using SQL
  •  Non-Callable statements
  •  prepared statement
  • both a and c (correct)

Description

  1. Statement which is used to run simple sql statements like select and update
  2. PrepareStatment is used to run Pre compiled sql.
  3. CallableStatement is used to execute the stored procedures.

19.Which class can never be a subclass in java?

  •  abstract class
  • parent class
  • Final class (correct)
  •  none of these

Description: A final class never be subclassed.

10.What is bean-managed persistence?

  •  When you implement entity or session bean methods to use SQL commands you provide. (correct)
  • When the bean’s container handles data storage and retrieval.
  • When the J2EE server is never shut down.
  • When changes to database data are lost during a crash.

Read more about Bean Persistence.

Comments

Leave a Comment