100+ Java Programming MCQs

These are Java Programming MCQs Questions for Basic electrical and electronics engineering

1. Which of this keyword can be used in a subclass to call the constructor of superclass?
a) super
b) this
c) extent
d) extends
Answer: a


2. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned
Answer: b


3. Which of these keywords can be used to prevent Method overriding?
a) static
b) constant
c) protected
d) final
Answer: d


4. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
a) super(void);
b) superclass.();
c) super.A();
d) super();
Answer: d


5. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status

{

/* insert qualifier here */ int MY_VALUE = 10;

}

a) final, native, private
b) final, static, protected
c) final, private, abstract
d) final, static, public
Answer: d

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


6. Which of these is supported by method overriding in Java?
a) Abstraction
b) Encapsulation
c) Polymorphism
d) None of the mentioned
Answer: c


7. What will be the output of the following Java program?

class Alligator

{

public static void main(String[] args)

{

int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

int [][]y = x;

System.out.println(y[2][1]);

}

}

a) 2
b) 3
c) 7
d) Compilation Error
Answer: c


8. What will be the output of the following Java program?

final class A

{

int i;

}

class B extends A

{

int j;

System.out.println(j + ” ” + i);

}

class inheritance

{

public static void main(String args[])

{

B obj = new B();

obj.display();

}

}

a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
Answer: d


9. What will be the output of the following Java program?

class Abc

{

public static void main(String[]args)

{

String[] elements = { “for”, “tea”, “too” };

String first = (elements.length > 0) ? elements[0]: null;

}

}

a) Compilation error
b) An exception is thrown at run time
c) The variable first is set to null
d) The variable first is set to elements[0]
Answer: d


10. What will be the output of the following Java program?

class A

{

int i;

public void display()

{

System.out.println(i);

}

}

class B extends A

{

int j;

public void display()

{

System.out.println(j);

}

}

class Dynamic_dispatch

{

public static void main(String args[])

{

B obj2 = new B();

obj2.i = 1;

obj2.j = 2;

A r;

r = obj2;

r.display();

}

}

a) 1
b) 2
c) 3
d) 4
Answer: b


These are Java Programming MCQs Questions for Basic electrical and electronics engineering

11. Which of these class is superclass of every class in Java?
a) String class
b) Object class
c) Abstract class
d) ArrayList class
Answer: b


12. Which of these method of Object class can clone an object?
a) Objectcopy()
b) copy()
c) Object clone()
d) clone()
Answer: c


13. Which of these method of Object class is used to obtain class of an object at run time?
a) get()
b) void getclass()
c) Class getclass()
d) None of the mentioned
Answer: c


14. Which of these keywords can be used to prevent inheritance of a class?
a) super
b) constant
c) class
d) final
Answer: d


15. Which of these keywords cannot be used for a class which has been declared final?
a) abstract
b) extends
c) abstract and extends
d) none of the mentioned
Answer: a

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


16. Which of these class relies upon its subclasses for complete implementation of its methods?
a) Object class
b) abstract class
c) ArrayList class
d) None of the mentioned
Answer: b


17. What will be the output of the following Java program?

abstract class A

{

int i;

abstract void display();

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class Abstract_demo

{

public static void main(String args[])

{

B obj = new B();

obj.j=2;

obj.display();

}

}

a) 0
b) 2
c) Runtime Error
d) Compilation Error
Answer: b


18. What will be the output of the following Java program?

class A

{

int i;

int j;

A()

{

i = 1;

j = 2;

}

}

class Output

{

public static void main(String args[])

{

A obj1 = new A();

A obj2 = new A();

System.out.print(obj1.equals(obj2));

}

}

a) false
b) true
c) 1
d) Compilation Error
Answer: a


19. What will be the output of the following Java code?

class Output

{

public static void main(String args[])

{

Object obj = new Object();

System.out.print(obj.getclass());

}

}

a) Object
b) class Object
c) class java.lang.Object
d) Compilation Error
Answer: c


20. What will be the output of the following Java code?

class A

{

int i;

int j;

A()

{

i = 1;

j = 2;

}

}

class Output

{

public static void main(String args[])

{

A obj1 = new A();

System.out.print(obj1.toString());

}

}

a) true
b) false
c) String associated with obj1
d) Compilation Error
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering

21. Which of these keywords are used to define an abstract class?
a) abst
b) abstract
c) Abstract
d) abstract class
Answer: b


22. Which of these is not abstract?
a) Thread
b) AbstractList
c) List
d) None of the Mentioned
Answer: a

23. If a class inheriting an abstract class does not define all of its function then it will be known as?
a) Abstract
b) A simple class
c) Static class
d) None of the mentioned
Answer: a

24. Which of these is not a correct statement?
a) Every class containing abstract method must be declared abstract
b) Abstract class defines only the structure of the class not its implementation
c) Abstract class can be initiated by new operator
d) Abstract class can be inherited
Answer: c


25. Which of these packages contains abstract keyword?
a) java.lang
b) java.util
c) java.io
d) java.system
Answer: a

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


26. What will be the output of the following Java code?

class A

{

public int i;

private int j;

}

class B extends A

{

void display()

{

super.j = super.i + 1;

System.out.println(super.i + ” ” + super.j);

}

}

class inheritance

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
Answer: d


27. What will be the output of the following Java code?

class A

{

public int i;

public int j;

A()

{

i = 1;

j = 2;

}

}

class B extends A

{

int a;

B()

{

super();

}

}

class super_use

{

public static void main(String args[])

{

B obj = new B();

System.out.println(obj.i + ” ” + obj.j)

}

}

a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
Answer: a


28. What will be the output of the following Java code?

class A

{

int i;

void display()

{

System.out.println(i);

}

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class method_overriding

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a) 0
b) 1
c) 2
d) Compilation Error
Answer: c


29. What will be the output of the following Java code?

class A

{

public int i;

protected int j;

}

class B extends A

{

int j;

void display()

{

super.j = 3;

System.out.println(i + ” ” + j);

}

}

class Output

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a) 1 2
b) 2 1
c) 1 3
d) 3 1
Answer: a


These are Java Programming MCQs Questions for Basic electrical and electronics engineering

30. Which of this keyword must be used to inherit a class?
a) super
b) this
c) extent
d) extends
Answer: d


31. A class member declared protected becomes a member of subclass of which type?
a) public member
b) private member
c) protected member
d) static member
Answer: b


32. Which of these is correct way of inheriting class A by class B?
a) class B + class A {}
b) class B inherits class A {}
c) class B extends A {}
d) class B extends class A {}
Answer: c


33. Which two classes use the Shape class correctly?

A. public class Circle implements Shape

{

private int radius;

}

B. public abstract class Circle extends Shape

{

private int radius;

}

C. public class Circle extends Shape

{

private int radius;

public void draw();

}

D. public abstract class Circle implements Shape

{

private int radius;

public void draw();

}

E. public class Circle extends Shape

{

private int radius;

public void draw()

{

/* code here */

}

}

F. public abstract class Circle implements Shape

{

private int radius;

public void draw()

{

/* code here */

}

}

a) B,E
b) A,C
c) C,E
d) T,H
Answer: a


34. What will be the output of the following Java program?

class A

{

int i;

void display()

{

System.out.println(i);

}

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class inheritance_demo

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a) 0
b) 1
c) 2
d) Compilation Error
Answer: c


35. What will be the output of the following Java program?

class A

{

int i;

}

class B extends A

{

int j;

void display()

{

super.i = j + 1;

System.out.println(j + ” ” + i);

}

}

class inheritance

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a) 2 2
b) 3 3
c) 2 3
d) 3 2
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


36. What will be the output of the following Java program?

class A

{

public int i;

public int j;

A()

{

i = 1;

j = 2;

}

}

class B extends A

{

int a;

B()

{

super();

}

}

class super_use

{

public static void main(String args[])

{

B obj = new B();

System.out.println(obj.i + ” ” + obj.j)

}

}

a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
Answer: a

37. What is not type of inheritance?
a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance
Answer: b


38. Using which of the following, multiple inheritance in Java can be implemented?
a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods
Answer: a


39. All classes in Java are inherited from which class?
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.Object
Answer: d


40. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
a) Protected
b) Private
c) Public
d) Static
Answer: b

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


41. If super class and subclass have same variable name, which keyword should be used to use super class?
a) super
b) this
c) upper
d) classname
Answer: a


42. Static members are not inherited to subclass.
a) True
b) False
Answer: b


43. Which of the following is used for implementing inheritance through an interface?
a) inherited
b) using
c) extends
d) implements
Answer: d


44. Which of the following is used for implementing inheritance through class?
a) inherited
b) using
c) extends
d) implements
Answer: c


45. What would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully
Answer: b

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


46. Does Java support multiple level inheritance?
a) True
b) False
Answer: a

47. Which of these class is superclass of String and StringBuffer class?
a) java.util
b) java.lang
c) ArrayList
d) None of the mentioned
Answer: b


48. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||
Answer: a


49. Which of this method of class String is used to obtain a length of String object?
a) get()
b) Sizeof()
c) lengthof()
d) length()
Answer: d


50. Which of these method of class String is used to extract a single character from a String object?
a) CHARAT()
b) chatat()
c) charAt()
d) ChatAt()
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


51. Which of these constructors is used to create an empty String object?
a) String()
b) String(void)
c) String(0)
d) None of the mentioned
Answer: a


52. Which of these is an incorrect statement?
a) String objects are immutable, they cannot be changed
b) String object can point to some other reference of String variable
c) StringBuffer class is used to store string in a buffer for later use
d) None of the mentioned
Answer: c


53. What will be the output of the following Java program?

class String_demo

{

public static void main(String args[])

{

char chars[] = {‘a’, ‘b’, ‘c’};

String s = new String(chars);

System.out.println(s);

}

}

a) a
b) b
c) c
d) abc
Answer: d


54. What will be the output of the following Java program?

class String_demo

{

public static void main(String args[])

{

int ascii[] = { 65, 66, 67, 68};

String s = new String(ascii, 1, 3);

System.out.println(s);

}

}

a) ABC
b) BCD
c) CDA
d) ABCD
Answer: b


55. What will be the output of the following Java program?

class String_demo

{

public static void main(String args[])

{

char chars[] = {‘a’, ‘b’, ‘c’};

String s = new String(chars);

String s1 = “abcd”;

int len1 = s1.length();

int len2 = s.length();

System.out.println(len1 + ” ” + len2);

}

}

a) 3 0
b) 0 3
c) 3 4
d) 4 3
Answer: d

These are Java Programming MCQs Questions for Basic electrical and electronics engineering

56. Which of these method of class String is used to extract more than one character at a time a String object?
a) getchars()
b) GetChars()
c) Getchars()
d) getChars()
Answer: d


57. Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?
a) getBytes()
b) GetByte()
c) giveByte()
d) Give Bytes()
Answer: a


58. In the following Java code, what can directly access and change the value of the variable name?

package test;

class Target

{

public String name = “hello”;

}

a) any class
b) only the Target class
c) any class in the test package
d) any class that extends Target
Answer: c


59. What will be the output of the following Java code?

public class Boxer1

{

Integer i;

int x;

public Boxer1(int y)

{

x = i+y;

System.out.println(x);

}

public static void main(String[] args)

{

new Boxer1 (new Integer(4));

}

}

a) The value “4” is printed at the command line
b) Compilation fails because of an error in line
c) A NullPointerException occurs at runtime
d) An IllegalStateException occurs at runtime
Answer: d


60. Which of these methods can be used to convert all characters in a String into a character array?
a) charAt()
b) both getChars() & charAt()
c) both toCharArray() & getChars()
d) all of the mentioned
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


61. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String c = “Hello i love java”;

int start = 2;

int end = 9;

char s[]=new char[end-start];

c.getChars(start,end,s,0);

System.out.println(s);

}

}

a) Hello, i love java
b) i love ja
c) lo i lo
d) llo i l
Answer: d


62. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String a = “hello i love java”;

System.out.println(a.indexOf(‘i’)+” “+a.indexOf(‘o’) +” “+a.lastIndexOf(‘i’)+” “+a.lastIndexOf(‘o’));

}

}

a) 6 4 6 9
b) 5 4 5 9
c) 7 8 8 9
d) 4 3 6 9
Answer: a


63. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

char c[]={‘a’, ‘1’, ‘b’ ,’ ‘ ,’A’ , ‘0’};

for (int i = 0; i < 5; ++i)

{

if(Character.isDigit(c[i]))

System.out.println(c[i]+” is a digit”);

if(Character.isWhitespace(c[i]))

System.out.println(c[i]+” is a Whitespace character”);

if(Character.isUpperCase(c[i]))

System.out.println(c[i]+” is an Upper case Letter”);

if(Character.isLowerCase(c[i]))

System.out.println(c[i]+” is a lower case Letter”);

i=i+3;

}

}

}

a)

a is a lower case Letter

is White space character

b)

b is a lower case Letter

is White space character

c)

a is a lower case Letter

A is an upper case Letter

d)

a is a lower case Letter

0 is a digit

Answer: c

64. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

char ch;

ch = “hello”.charAt(1);

System.out.println(ch);

}

}

a) h
b) e
c) l
d) o
Answer: b

65. Which of these method of class String is used to compare two String objects for their equality?
a) equals()
b) Equals()
c) isequal()
d) Isequal()
Answer: a

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


66. Which of these methods is used to compare a specific region inside a string with another specific region in another string?
a) regionMatch()
b) match()
c) RegionMatches()
d) regionMatches()
Answer: d


67. Which of these methods of class String is used to check whether a given object starts with a particular string literal?
a) startsWith()
b) endsWith()
c) Starts()
d) ends()
Answer: a


68. What is the value returned by function compareTo() if the invoking string is less than the string compared?
a) zero
b) value less than zero
c) value greater than zero
d) none of the mentioned
Answer: b


69. Which of these data type value is returned by equals() method of String class?
a) char
b) int
c) boolean
d) all of the mentioned
Answer: c


70. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String c = “Hello i love java”;

boolean var;

var = c.startsWith(“hello”);

System.out.println(var);

}

}

a) true
b) false
c) 0
d) 1
Answer: b

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


71. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String s1 = “Hello i love java”;

String s2 = new String(s1);

System.out.println((s1 == s2) + ” ” + s1.equals(s2));

}

}

a) true true
b) false false
c) true false
d) false true
Answer: d


72. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String s1 = “Hello”;

String s2 = new String(s1);

String s3 = “HELLO”;

System.out.println(s1.equals(s2) + ” ” + s2.equals(s3));

}

}

a) true true
b) false false
c) true false
d) false true
Answer: c


73. In the following Java code, which code fragment should be inserted at line 3 so that the output will be: “123abc 123abc”?

1. StringBuilder sb1 = new StringBuilder(“123”);

2. String s1 = “123”;

3. // insert code here

4. System.out.println(sb1 + ” ” + s1);

a) sb1.append(“abc”); s1.append(“abc”);
b) sb1.append(“abc”); s1.concat(“abc”);
c) sb1.concat(“abc”); s1.append(“abc”);
d) sb1.append(“abc”); s1 = s1.concat(“abc”);
Answer: d


74. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

String chars[] = {“a”, “b”, “c”, “a”, “c”};

for (int i = 0; i < chars.length; ++i)

for (int j = i + 1; j < chars.length; ++j)

if(chars[i].compareTo(chars[j]) == 0)

System.out.print(chars[j]);

}

}

a) ab
b) bc
c) ca
d) ac
Answer: d

75. Which of this method of class String is used to extract a substring from a String object?
a) substring()
b) Substring()
c) SubString()
d) None of the mentioned
Answer: a

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


76. What will s2 contain after following lines of Java code?

String s1 = “one”;

String s2 = s1.concat(“two”)

a) one
b) two
c) onetwo
d) twoone
Answer: c


77. Which of these method of class String is used to remove leading and trailing whitespaces?
a) startsWith()
b) trim()
c) Trim()
d) doTrim()
Answer: b


78. What is the value returned by function compareTo() if the invoking string is greater than the string compared?
a) zero
b) value less than zero
c) value greater than zero
d) none of the mentioned
Answer: c


79. Which of the following statement is correct?
a) replace() method replaces all occurrences of one character in invoking string with another character
b) replace() method replaces only first occurrences of a character in invoking string with another character
c) replace() method replaces all the characters in invoking string with another character
d) replace() replace() method replaces last occurrence of a character in invoking string with another character
Answer: a


80. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

String c = ” Hello World “;

String s = c.trim();

System.out.println(“\””+s+”\””);

}

}

a) “”Hello World””
b) “”Hello World”
c) “Hello World”
d) Hello world
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


81. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

String s1 = “one”;

String s2 = s1 + ” two”;

System.out.println(s2);

}

}

a) one
b) two
c) one two
d) compilation error
Answer: c


82. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

String s1 = “Hello”;

String s2 = s1.replace(‘l’,’w’);

System.out.println(s2);

}

}

a) hello
b) helwo
c) hewlo
d) hewwo
Answer: d


83. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

String s1 = “Hello World”;

String s2 = s1.substring(0 , 4);

System.out.println(s2);

}

}

a) Hell
b) Hello
c) Worl
d) World
Answer: a


84. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{ String s = “Hello World”;

int i = s.indexOf(‘o’);

int j = s.lastIndexOf(‘l’);

System.out.print(i + ” ” + j);

}

}

a) 4 8
b) 5 9
c) 4 9
d) 5 8
Answer: c

85. Which of these class is used to create an object whose character sequence is mutable?
a) String()
b) StringBuffer()
c) String() & StringBuffer()
d) None of the mentioned
Answer: b

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


86. Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
a) concat()
b) append()
c) join()
d) concatenate()
Answer: b


87. Which of these method of class StringBuffer is used to find the length of current character sequence?
a) length()
b) Length()
c) capacity()
d) Capacity()
Answer: a


88. What is the string contained in s after following lines of Java code?

StringBuffer s new StringBuffer(“Hello”);

s.deleteCharAt(0);

a) Hell
b) ello
c) Hel
d) llo
Answer: b


89. Which of the following statement is correct?
a) reverse() method reverses all characters
b) reverseall() method reverses all characters
c) replace() method replaces first occurrence of a character in invoking string with another character
d) replace() method replaces last occurrence of a character in invoking string with another character
Answer: a


90. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

String a = “hello i love java”;

System.out.println(a.indexOf(‘e’)+” “+a.indexOf(‘a’)+” “+a.lastIndexOf(‘l’)+” “+a.lastIndexOf(‘v’));

}

}

a) 6 4 6 9
b) 5 4 5 9
c) 7 8 8 9
d) 1 14 8 15
Answer: d

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


91. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

StringBuffer c = new StringBuffer(“Hello”);

c.delete(0,2);

System.out.println(c);

}

}

a) He
b) Hel
c) lo
d) llo
Answer: d


92. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

StringBuffer c = new StringBuffer(“Hello”);

StringBuffer c1 = new StringBuffer(” World”);

c.append(c1);

System.out.println(c);

}

}

a) Hello
b) World
c) Helloworld
d) Hello World
Answer: d


93. What will be the output of the following Java program?

class output

{

public static void main(String args[])

{

StringBuffer s1 = new StringBuffer(“Hello”);

StringBuffer s2 = s1.reverse();

System.out.println(s2);

}

}

a) Hello
b) olleH
c) HelloolleH
d) olleHHello
Answer: b


94. What will be the output of the following Java program?

class output

{

class output

{

public static void main(String args[])

{

char c[]={‘A’, ‘1’, ‘b’ ,’ ‘ ,’a’ , ‘0’};

for (int i = 0; i < 5; ++i)

{

i++;

if(Character.isDigit(c[i]))

System.out.println(c[i]+” is a digit”);

if(Character.isWhitespace(c[i]))

System.out.println(c[i]+” is a Whitespace character”);

if(Character.isUpperCase(c[i]))

System.out.println(c[i]+” is an Upper case Letter”);

if(Character.isLowerCase(c[i]))

System.out.println(c[i]+” is a lower case Letter”);

i++;

}

}

}

a)

a is a lower case Letter

is White space character

b)

b is a lower case Letter

is White space character

c)

1 is a digit

a is a lower case Letter

d)

a is a lower case Letter

0 is a digit

Answer: c

95. Which of these methods of class StringBuffer is used to extract a substring from a String object?
a) substring()
b) Substring()
c) SubString()
d) None of the mentioned
Answer: a

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


96. What will s2 contain after following lines of Java code?

StringBuffer s1 = “one”;

StringBuffer s2 = s1.append(“two”)

a) one
b) two
c) onetwo
d) twoone
Answer: c


97. Which of this method of class StringBuffer is used to reverse sequence of characters?
a) reverse()
b) reverseall()
c) Reverse()
d) reverseAll()
Answer: a


98. Which of this method of class StringBuffer is used to get the length of the sequence of characters?
a) length()
b) capacity()
c) Length()
d) Capacity()
Answer: a


99. Which of the following are incorrect form of StringBuffer class constructor?
a) StringBuffer()
b) StringBuffer(int size)
c) StringBuffer(String str)
d) StringBuffer(int size , String str)
Answer: d


100. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

StringBuffer c = new StringBuffer(“Hello”);

System.out.println(c.length());

}

}

a) 4
b) 5
c) 6
d) 7
Answer: b
7. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

StringBuffer sb=new StringBuffer(“Hello”);

sb.replace(1,3,”Java”);

System.out.println(sb);

}

}

a) Hello java
b) Hellojava
c) HJavalo
d) Hjava
Answer: c

These are Java Programming MCQs Questions for Basic electrical and electronics engineering


101. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

StringBuffer s1 = new StringBuffer(“Hello”);

s1.setCharAt(1,’x’);

System.out.println(s1);

}

}

a) xello
b) xxxxx
c) Hxllo
d) Hexlo
Answer: c


102. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

StringBuffer s1 = new StringBuffer(“Hello World”);

s1.insert(6 , “Good “);

System.out.println(s1);

}

}

a) HelloGoodWorld
b) HellGoodoWorld
c) HellGood oWorld
d) Hello Good World
Answer: d


103. What will be the output of the following Java code?

class output

{

public static void main(String args[])

{

StringBuffer s1 = new StringBuffer(“Hello”);

s1.insert(1,”Java”);

System.out.println(s1);

}

}

a) hello
b) java
c) Hello Java
d) HJavaello
Answer: d


These are Java Programming MCQs Questions for Basic electrical and electronics engineering

More in this category:- Click Here



These are Java Programming MCQs Questions for Basic electrical and electronics engineering


The content uploaded on this website is for reference purposes only. Please do it yourself first.