Vidyalelo
Java Programming · all questions

Constructors and Methods
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

140

Questions

2/7

Page

Pick an option on a question to see the right answer and solution.

Which keyword is used to declare a method that cannot be overridden in Java?

Select an option to see the answer and solution.

What is method hiding in Java?

Select an option to see the answer and solution.

What is the purpose of the "return" statement in a method in Java?

Select an option to see the answer and solution.

In Java, can a method have the same name as the class?

Select an option to see the answer and solution.

What is method signature in Java?

Select an option to see the answer and solution.

In Java, which access modifier allows a method to be accessed from any class in any package?

Select an option to see the answer and solution.

What is a non-static (instance) method in Java?

Select an option to see the answer and solution.

In Java, what does the "final" keyword indicate when used with a method?

Select an option to see the answer and solution.

What is the difference between a method declaration and a method definition in Java?

Select an option to see the answer and solution.

In Java, what is the purpose of method overloading?

Select an option to see the answer and solution.

What is the expected output?
public class Profile {
         private Profile(int w) { // line 1
                  System.out.print(w);
         }
         public static Profile() { // line 5
                  System.out.print (10);
         }
         public static void main(String args[]) {
                  Profile obj = new Profile(50);
         }
}

Select an option to see the answer and solution.

The following code contains one compilation error, find it?
public class Test {
	Test() {    }  // line 1
	static void Test() {  this(); } // line 2  
	public static void main(String[] args) { // line 3
		Test(); // line 4
	}
}

Select an option to see the answer and solution.

What will be the return type of a method that not returns any value?

Select an option to see the answer and solution.

Which of the following options is the best for generating random integer 0 or 1?

Select an option to see the answer and solution.

What is Math.floor(3.6)?

Select an option to see the answer and solution.

In which area of memory, the system stores parameters and local variables whenever a method is invoked?

Select an option to see the answer and solution.

What is the expected output?
public class Profile {
	private Profile(int w) { // line 1
		System.out.print(w);
	}
	public final Profile() { // line 5
		System.out.print(10);
	}
	public static void main(String args[]) {
		Profile obj = new Profile(50);
	}
}

Select an option to see the answer and solution.

What is the expected output?
class Animal {
	Animal() {
		System.out.println("Animal");
	}
}
class Wild extends Animal{
	Wild() {
		System.out.println("Wild");
		super();
	}
}
public class Test {
	public static void main(String args[]) {
		Wild wild = new Wild();
	}
}

Select an option to see the answer and solution.

Which of the modifier can't be used for constructors?

Select an option to see the answer and solution.

The variables declared in a class for the use of all methods of the class are called

Select an option to see the answer and solution.