© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Classes, Objects and Access Specifiers ▼

Java Interview Questions On Classes, Objects and Access Specifiers

27. What is the result when you compile and run the following code?
class A {
A(double d) {
System.out.println("Printing the value of d is 10");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}

[a] Printing the value of d is 10 followed by Class B Constructor
[b] Printing the value of d is 10
[c] Compile time error
[d] Run time error

Answer

[c] Compile time error

28. What is the result when you compile and run the following code?
public class MyClass {
void MyClass() {
System.out.print(" Calling constructor");
}
public static void main( String arg[]) {
MyClass mc = new MyClass();
}
}
[a] Compile time error
[b] Runtime error
[c] Calling constructor printed
[d] Compiles successfully, no output at runtime.

Answer
[d] Compiles successfully , no output at runtime.

29. Select all the correct answers from the following?
[a] Default constructors takes no arguments.
[b] Constructors are defined with the name same name as class.
[c] A "void" is a valid return type for constructors.
[d] Default constructor is provided by the compiler, if no other constructors are defined.

Answer
[a] Default constructors takes no arguments.
[b] Constructors are defined with the name same name as class
[d] Default constructor is provided by the compiler , if no other constructors are defined.

30. Which of the statements are true?
[a] Overridden methods have the same method name and signature
[b] Overloaded methods have the same method name and signature
[c] Overridden methods have the same method name and different signature
[d] Overloaded methods have the same method name and different signature

Answer
[a] Overridden methods have the same method name and signature
[d] Overloaded methods have the same method name and different signature

Next
1 2 3 4 5 6 7 8
SLogix Student Projects
bottom