Online Test

  • Facebook
  • Google
  • LinkedIn
  • Twitter
Question: 1
A class can have many methods with the same name as long as the number of parameters or type of parameters 
is different. This OOP concept is known as
Method Invocating
Method Overriding
Method Labeling
Method Overloading

Question: 2
//Which is the correct option of this programs?

package test;

public class MainApp {
	public static void main(String[] srgs) {
		try {
			checkException();
			System.out.print("A");
		} catch (RuntimeException ex) {
			System.out.print("B");
		} catch (Exception ex) {
			System.out.print("C");
		} finally {
			System.out.print("D");
		}
		System.out.print("10");
	}

	public static void checkException() {
		throw new RuntimeException();
	}
}
BD10
BD
BCD
BCD10

Question: 3
//What will be the correct option for the following program

package com.javatutsworld.test;

public class MainApp {
	public static void main(String[] args) {
		Student s = new Student(-10);
		s.showme();
	}
}

class Student {
	int age = 20;

	Student(int a) {
		if (age < 20)
			return;
		age = a;
	}

	void showme() {
		System.out.println(age);
	}
}
Compile time error.
Run time error
-10
It will throw an exception

Question: 4
//Which is the correct option of this programs?


package test;

public class MainApp {
	public static void aTestMethod() throws Exception {
		try {
			throw new Exception();
		} finally {
			System.out.print("finally");
		}
	}

	public static void main(String[] srgs) {
		try {
			aTestMethod();
		} catch (Exception e) {
			System.out.print("Exception");
		}
		System.out.print("finished");
	}
}
finallyExceptionfinished
Exceptionfinished
compilation fails
finallyException

Question: 5
//Which two statements are true?

package test;

public class MainApp {
	public static void main(String args[]) {
		
		String #name = "Joseph";

		int $age = 24;

		Double _height = 120.5;

		double ~temp = 35.5;
	}
}
String #name = "Joseph"; will not compile.
int $age = 24; will not compile.
Double _height = 120.5; will not compile.
None of the above

Question: 6
//What will be the result?

public class MainApp {
	public static void main(String[] args) {

		String str = "null";
		if (str == null) {
			System.out.println("null");

		} else (str.length() == 0) {

			System.out.println("zero");

		}else {
			System.out.println("hello");

		}
	}
}
null
zero
hello
Compilation fails.

Question: 7
//Which is the default value of the local variables?
null
0
depends on the data type
no default value for local variables

Question: 8
//Which code should be inserted before MainApp class at "insert code here" 
to compile and run MainApp to print "IndiaIndia" ?



package test;

public class TestStatic {

	public static String print(String s) {
		return s + s;
	}

}


//another class MainApp


package test;

// insert code here

public class MainApp {

	public static void main(String[] args) {

		System.out.println(print("India"));

	}

}
import utils.*;
static import utils.*;
import static test.TestStatic.print;
static import utils.TestStatic.print;

Question: 9
//What will be the correct option for the following program

package com.javatutsworld.test;

public class MainApp {
	public static void main(String[] args) {
		Test t = new Test();
	}
}

class Test {
	int a;

	Test() {
		System.out.println("ABC const");
	}
}
Compile time error.
Run time error
ABC const
Nothing will print

Question: 10
Which of the statement given below is incorrect for Immutable Class?
Immutable Classes don't have setter methods.
All fields are final and private
Class is declared final to prevent subclasses
None of the above

      Advertisements