What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}A. Compilation Fails
B. Prints 0
C. Prints 10
D. Prints 7
E. None of these
Select an option to see the answer and solution.
Which component is responsible to run java program?
Select an option to see the answer and solution.
Which of the below is not a Java Profiler?
A. JVM
B. JConsole
C. JProfiler
D. Eclipse Profiler
Select an option to see the answer and solution.
What is true about constructor?
A. It can contain return type
B. It can take any number of parameters
C. It can have any non access modifiers
D. Constructor cannot throw an exception
Select an option to see the answer and solution.
Which statement is true about java?
A. Platform independent programming language
B. Platform dependent programming language
C. Code dependent programming language
D. Sequence dependent programming language
Select an option to see the answer and solution.
What is not the use of "this" keyword in Java?
A. Passing itself to another method
B. Calling another constructor in constructor chaining
C. Referring to the instance variable when local variable has the same name
D. Passing itself to method of the same class
Select an option to see the answer and solution.
When does method overloading is determined?
A. At run time
B. At compile time
C. At coding time
D. At execution time
Select an option to see the answer and solution.
Which of these operators is used to allocate memory for an object?
A. malloc
B. alloc
C. new
D. give
Select an option to see the answer and solution.
What is true about Class.getInstance()?
A. Class.getInstance calls the constructor
B. Class.getInstance is same as new operator
C. Class.getInstance needs to have matching constructor
D. Class.getInstance creates object if class does not have any constructor
Select an option to see the answer and solution.
What will be the output of the following Java program?
class recursion
{
int func (int n)
{
int result;
result = func (n - 1);
return result;
}
}
class Output
{
public static void main(String args[])
{
recursion obj = new recursion() ;
System.out.print(obj.func(12));
}
}A. 0
B. 1
C. Compilation Error
D. Runtime Error
Select an option to see the answer and solution.
Method overriding is combination of inheritance and polymorphism?
Select an option to see the answer and solution.
Which exception is thrown when java is out of memory?
A. MemoryFullException
B. MemoryOutOfBoundsException
C. OutOfMemoryError
D. MemoryError
Select an option to see the answer and solution.
What is Recursion in Java?
A. Recursion is a class
B. Recursion is a process of defining a method that calls other methods repeatedly
C. Recursion is a process of defining a method that calls itself repeatedly
D. Recursion is a process of defining a method that calls other methods which in turn call again this method
Select an option to see the answer and solution.
Which function is used to perform some action when the object is to be destroyed?
A. finalize()
B. delete()
C. main()
D. none of the mentioned
Select an option to see the answer and solution.
Which of these statement is incorrect?
A. Every class must contain a main() method
B. Applets do not require a main() method at all
C. There can be only one main() method in a program
D. main() method must be made public
Select an option to see the answer and solution.
What will be the output of the following Java code?
class box
{
int width;
int height;
int length;
int volume;
void finalize()
{
volume = width*height*length;
System.out.println(volume);
}
protected void volume()
{
volume = width*height*length;
System.out.println(volume);
}
}
class Output
{
public static void main(String args[])
{
box obj = new box();
obj.width=5;
obj.height=5;
obj.length=6;
obj.volume();
}
}A. 150
B. 200
C. Run time error
D. Compilation error
Select an option to see the answer and solution.
Which of the following is a garbage collection technique?
A. Cleanup model
B. Mark and sweep model
C. Space management model
D. Sweep model
Select an option to see the answer and solution.
What will be the output of the following Java program?
class recursion
{
int func (int n)
{
int result;
if (n == 1)
return 1;
result = func (n - 1);
return result;
}
}
class Output
{
public static void main(String args[])
{
recursion obj = new recursion() ;
System.out.print(obj.func(5));
}
}A. 0
B. 1
C. 120
D. None of the mentioned
Select an option to see the answer and solution.
What is true about private constructor?
A. Private constructor ensures only one instance of a class exist at any point of time
B. Private constructor ensures multiple instances of a class exist at any point of time
C. Private constructor eases the instantiation of a class
D. Private constructor allows creating objects in other classes
Select an option to see the answer and solution.
Where is a new object allocated memory?
A. Young space
B. Old space
C. Young or Old space depending on space availability
D. JVM
Select an option to see the answer and solution.