What is the output of this program?
1.class Abc
2.{
3.public static void .main(String[]args)
4.{
5.String[] elements = { "for", "tea", "too" };
6.String first = (elements.length > 0) ? elements[0]: null;
7.}
8.}
What is the return type of a method that does not returns any value?
What is the output of this program?
1.class test {
2.int a;
3.int b;
4.void meth(int i , int j) {
5.i *= 2;
6.j /= 2;
7.}
8.}
9.class Output {
10.public static void main(String args[])
11.{
12.test obj = new test();
13.int a = 10;
14.int b = 20;
15.obj.meth(a , b);
16.System.out.println(a + " " + b);
17.}
18.}
What is the output of this program?
1.class String_demo {
2. public static void main(String args[])
3.{
4.char chars[] = {'a', 'b', 'c'};
5.String s = new String(chars);
6.System.out.println(s);
7.}
8.}
What is the output of this program?
1.class A {
2.int i;
3.int j;
4.A() {
5.i = 1;
6. j = 2;
7.}
8.}
9.class Output {
10.public static void main(String args[])
11.{
12.A obj1 = new A();
13.System.out.print(obj1.toString());
14.}
15.}
In below code, what can directly access and change the value of the variable name?
1.package test;
2.class Target
3.{
4.public String name = "hello";
5.}
Which of these keywords is used to define packages in Java?
What is the output of this program?
1.import java.util.*;
2.class stack {
3.public static void main(String args[]) {
4.Stack obj = new Stack();
5.obj.push(new Integer(3));
6.obj.push(new Integer(2));
7.obj.pop();
8.obj.push(new Integer(5));
9.System.out.println(obj);
10.}
11.}
What is the output of this program?
1.import java.util.*;
2.class vector {
3.public static void main(String args[]) {
4.Vector obj = new Vector(4,2);
5.obj.addElement(new Integer(3));
6.obj.addElement(new Integer(2));
7.obj.addElement(new Integer(5)); 8.System.out.println(obj.capacity());
9.}
10.}
With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? 1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
What is the value returned by unction compareTo() if the invoking string is less than the string compared?
Which of these method is used to change an element in a LinkedList Object?
Which of the following statements are incorrect?
What is the string contained in s after following lines of code?
StringBuffer s new StringBuffer(“Hello”);
s.deleteCharAt(0);
What is the output of this program?
1.import java.util.*;
2.class Arraylist {
3.public static void main(String args[]) {
4.ArrayList obj = new ArrayList();
5.obj.add("A");
6.obj.add("B");
7.obj.add("C");
8.obj.add(1, "D");
9.System.out.println(obj);
10.}
11.}
-
-
-
-
Which function is used to perform some action when the object is to be destroyed?
Which of these lines of code will give better performance?
1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))
Which of these method is used to change an element in a LinkedList Object?
What is the output of relational operators?
Which of these method is used to add an element to the start of a LinkedList object?
Which of these is a mechanism for naming and visibility control of a class and its content?
Which of these operators can be used to concatenate two or more String objects?
Which of these method of class String is used to remove leading and trailing whitespaces?
What is the output of this program?
1.import java.util.*;
2.class Array {
3.public static void main(String args[]) {
4.int array[] = new int [5];
5.for (int i = 5; i > 0; i--)
6.array[5-i] = i;
7.Arrays.fill(array, 1, 4, 8);
8.for (int i = 0; i < 5 ; i++)
9.System.out.print(array[i]);
10.}
11.}
Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
Which of these class is used to create an object whose character sequence is mutable?
What is the output of this program?
1.import java.net.*;
2.class networking {
3.public static void main(String[] args) throws Exception {
4.URL obj = new URL("http://www.sanfoundry.com/javamcq");
5.URLConnection obj1 = obj.openConnection(); 6.System.out.print(obj1.getLastModified);
7.}
8.}
Note: Host URL was last modified on july 18 tuesday 2013 .
Which of these is an instance variable of class httpd?
What is the output of this program?
1.class jump_statments {
2.public static void main(String args[])
3.{
4.int x = 2;
5.int y = 0;
6.for ( ; y < 10; ++y) {
7.if (y % x == 0)
8.continue;
9.else if (y == 8)
10.break;
11.else
12.System.out.print(y + " ");
13.}
14.}
15.}
Which of these keywords is used to define interfaces in Java?
Which of these tranfer protocol must be used so that URL can be accessed by URLConnection class object?
What is the output of this program?
1.class string_class {
2.public static void main(String args[])
3.{
4.String obj = "I LIKE JAVA";
5.System.out.println(obj.length());
6.}
7.}
Which of the following package stores all the standard java classes?
Which of these methods can be used to convert all characters in a String into a character array?
What is the output of this program?
1.interface calculate {
2.void cal(int item);
3.}
4.class display implements calculate {
5.int x;
6.public void cal(int item) {
7.x = item * item;
8.}
9.}
10.class interfaces {
11.public static void main(String args[]) {
12.display arr = new display;
13.arr.x = 0;
14.arr.cal(2);
15.System.out.print(arr.x);
16.}
17.}
Which of the following package stores all the standard java classes?
What is the output of this program?
1.class output {
2.public static void main(String args[])
3.{
4.StringBuffer s1 = new StringBuffer("Hello");
5.s1.insert(1,"Java");
6.System.out.println(s1);
7.}
8.}
What is the output of this program?
1.class A {
2.final public int calculate(int a, int b) { return 1; }
3.}
4.class B extends A {
5.public int calculate(int a, int b) { return 2; }
6.}
7.public class output {
8.public static void main(String args[])
9.{
10.B object = new B();
11.System.out.print("b is b.calculate(0, 1));
12.}
13.}
What is the process by which we can control what parts of a program can access the members of a class?