Java Quiz 03

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Java Quiz 01

Q1. Predict the output of following Java program?

class Test {

int i;

class Main {

public static void main(String args[]) {

Test t;

System.out.println(t.i);

Compile error

Garbage value

Runtime

Q2 . What would be the behaviour if this() and super() used in a method?

Runtime error

Throws exception

compile time error

Runs successfully
Q3. Which statement is not true in java language?
A public member of a class can be accessed in all the packages.

A private member of a class cannot be accessed by the methods of the same class.

A private member of a class cannot be accessed from its derived class.

A protected member of a class can be accessed from its derived class.

Q4. To prevent any method from overriding, we declare the method as,

Static

Const

 final 

 abstract

Q5. What is the output of the following program:?

public class testmeth


{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” , “);
m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}

1,3
2,3

1,1

3,4
Q6. What is false about constructor?

Constructors cannot be synchronized in Java

 Java does not provide default copy constructor

Constructor can have a return type

“this” and “super” can be used in a constructor


Q7. What is true about constructor?
It can contain return type
It can take any number of parameters
It can have any non access modifiers
Constructor cannot throw an exception
Q8. Abstract class cannot have a constructor.
True
False

Q9What is true about protected constructor?


Protected constructor can be called directly
Protected constructor can only be called using super()
Protected constructor can be used outside package
protected constructor can be instantiated even if child is in a different package

Q10.What is not the use of “this” keyword in Java?


Passing itself to another method
Calling another constructor in constructor chaining
Referring to the instance variable when local variable has the same name
Passing itself to method of the same class

. Which keyword is used by the method to refer to the object that invoked it?

Import
Catch
Abstract
This
Which of the following is a method having same name as that of its class?
finalize
delete
class
constructor

Which operator is used by Java run time implementations to free the memory of an
object when it is no longer needed?
delete
free
new
none of the mentioned

 Which one of the following is not true?


A class containing abstract methods is called an abstract class.
Abstract methods should be implemented in the derived class.
An abstract class cannot have non-abstract methods.
A class must be qualified as ‘abstract’ class, if it contains one abstract method.

 Which of the following variable declaration would NOT compile in a java program?
int var;
 int VAR; 
int var_1;
int 1_var;.

Which of the following is TRUE?


In java, an instance field declared public generates a compilation error.
int is the name of a class available in the package java.lang
Instance variable names may only contain letters and digits.
A class has always a constructor (possibly automatically supplied by the java compiler).

Consider the following statements:


I. A class can be declared as both abstract and final.
II. A class declared as final can be extended by defining a sub-class.
III. Resolving calls to methods dynamically at run-time is called late binding.
IV. The class Object defined by Java need not be a super class of all other classes.
Identify the correct statement from the following:
Both (I) and (II) above
Both (II) and (IV) above
Only (III) above.
Both (III) and (IV) above

Consider the following data types in Java :

I. Int II. Boolean III. Double IV. String V. Array.

Which of them are simple data types?

Both (I) and (II) above 


 (I), (II), (III) and (IV) above
(II) and (III) above
 (I), (II) and (III)

You might also like