0

Basics of Java

Description: The Java is programming language.The objective questions include program and other object oriented technology.
Number of Questions: 25
Created by:
Tags: Applet Data Types Variables and Storage Classes Java/Oracle /C/C++ Strings and Character Arrays File Handling
Attempted 0/25 Correct 0 Score 0

Which of the following is not an access specifier?

  1. Private

  2. Static

  3. Public

  4. Protected

  5. None of the above


Correct Option: B
Explanation:

Static is modifier, it is not an access specifier.

Which type of inheritance is not possible/allowed in Java using extends keyword?

  1. Multiple

  2. Multilevel

  3. Single

  4. Hierarchical

  5. None of the above


Correct Option: A
Explanation:

Multiple inheritance is not possible by using extends keyword. We can implement interface to do multiple inheritance.

________ modifier is often used in multithreaded programs.

  1. Native

  2. Static

  3. Syncronized

  4. Final

  5. None of the above


Correct Option: C
Explanation:

Syncronized modifier is often used in multithreaded programs.

Which of the following is/are difference(s) between class and interface? (a) Class can be instantiated, while interface cannot. (b) Class is a collection of data members and methods, while Interface consists of constants and method declarations. (c) Any class can extend another class using keyword extends, while interfaces are implemented using keyword implements.

  1. Only (a)

  2. Only (a) and (b)

  3. Only (b) and (c)

  4. All (a), (b) and (c)

  5. None of the above


Correct Option: D
Explanation:

All a,b and c are correct.

Which of the following cannot generate an event?

  1. TextArea

  2. TextField

  3. Label

  4. Buttons

  5. None of the above


Correct Option: C
Explanation:

Label cannot generate an event. It just displays the content.

Which of the following keywords is not present in Java?

  1. goto

  2. break

  3. continue

  4. all of the above

  5. none of these


Correct Option: A
Explanation:

The goto keyword sometimes may cause program to go in infinity. The goto statement is not present in Java.

Which of the following is/are not the method(s) in life cycle of an applet? (a) init (b) start (c) stop (d) destroy (e) paint

  1. Only (a) and (d)

  2. Only (e)

  3. Only (b) and (c)

  4. None of the above

  5. All of the above


Correct Option: B
Explanation:

Whenever an applet is started or initiated, paint() method is called but it is not included in the life cycle of an applet.

Which of the following features present in C/C++ is not supported by Java?

  1. Inheritance

  2. Function overloading

  3. Pointer

  4. Arrays

  5. None of the above


Correct Option: C
Explanation:

Pointers are not used in Java, so that invalid memory access is denied.

To which class does the method to UpperCase() belong?

  1. String class

  2. Char class

  3. Math class

  4. String buffer class

  5. None of the above


Correct Option: B
Explanation:

The Char class is a wrapper class, which provides following methods: toUpperCase(),toLowerCase(),isLetter(),isSpace(),isDigit()

What is the output of a Java compiler?

  1. Executable code

  2. Bytecode

  3. Bitcode

  4. Assembly language code

  5. None of these


Correct Option: B
Explanation:

The output of compiler is bytecode, which is a platform independent file.

What will be the output of following code: class pattern { public static void main(String arts[]) String a = "WELCOME", b; for(i=0; i<=a.length(); i ++;) { b= a.substring(0,i); system.out.print(b); } } }

  1. WWEWELWELCWELCOWELCOMWELCOM

  2. WELCOMEWELCOMWELCOWELCWELWEW

  3. W WE WEL WELC WELCO WELCOM WELCOME

  4. WELCOME

  5. None of the above


Correct Option: A
Explanation:

A is an array having value “WELCOME “. So at 0th position W is present.i=0a.substring(0,0) =>Wi=1a.substring(0,1) =>WEi=2a.substring(0,2) =>WELTherefore option ‘1’ is correct answer.

What is the use of Super keyword in Java?

  1. Used for inheritance

  2. Allows child class to call parameterized constructor of the class

  3. Used for making a function inline

  4. Used for making class or function template

  5. Allows parent class to call parameterized constructor of child class


Correct Option: B
Explanation:

In constructor calling, default constructor of parent class gets automatically called. Super keyword allows child class to call parameterized constructor of the parent class.

Which of the following functions is performed by the program given below? class Demo { public static void main(String args[]) { int m, n=4325; int s=0; while(n!=0) { m=n%10; s=s+m; n=n/10; } System.out.println(“…………”+s); } }

  1. Separates digits and reverses the number

  2. Reverses the number

  3. Addition of digits of the given input number

  4. All of the above

  5. None of the above


Correct Option: C
Explanation:

The above code fragment separates the digits and does addition of digits of the given number 4325. The output of the given program code is 14.

What is the difference between == and equals()?

  1. Both == and equals() check whether two objects belong to the same instance.

  2. == compares characters inside a string object, while equals() check whether two objects belong to the same instance.

  3. Both == and equals() compare characters inside the string object.

  4. == operator checks whether two objects belong to the same instance, while equals() compares characters inside the string object.

  5. None of the above


Correct Option: D
Explanation:

This is the correct answer as == operator checks whether two objects belong to the same instance, while equals() compares characters inside the string object.

Which of the following accesses is/are provided by RandomAccessFile class?

  1. r, rw

  2. rws, rwd

  3. only rw

  4. r, rw, rws, rwd

  5. none of the above


Correct Option: D
Explanation:

Following are the accesses provided by RandomAccessFile classr: r, rw, rws, rwd

class Demo {public static void main(String[] args) {StringBufferch=new StringBuffer(DAD); StringBufferst=new StringBuffer(ch);st=st.reverse(); String str=new String(st); String sta=new String(ch); if(str.equals(sta)) System.out.println(…….); else System.out.print(……..);}}

The above written program code

  1. checks whether the two strings are equal or not

  2. reverses the string

  3. check whether the string is palindrome or not

  4. compares the StringBuffer and String object

  5. none of the above


Correct Option: C
Explanation:

The above code checks whether the given string is palindrome or not.

Which of the following is/are not the built in exception(s) in Java? (a) ArrayIndexOutOfBoundsException (b) NullPointerException (c) Arithmetic Exception (d) IOException

  1. Only (a)

  2. Only (a) , (b), (c)

  3. Only (a) and (b)

  4. All (a), (b), (c), (d) are built in exceptions.

  5. None of the above


Correct Option: D
Explanation:

The IOException get raised whenever an input output task is attempted by user using standard I/O device.So all a,b,c,d are Built in Exception in Java.

Which of the following is not a built in class in Java?

  1. String class

  2. Math class

  3. Applet class

  4. Util class

  5. StringBuffer class


Correct Option: D
Explanation:

The util is a package which has different classes like Date, etc.

Which of the following is/are not the difference(s) between Abstract Class and Interfaces? (a) A class can implement several interfaces but may extend only one abstract class. (b) No constructors are provided by interfaces, while abstract class provides constructors. (c) Variables in interfaces must me public, static or final. There is no such restriction in abstract class.

  1. Only (a)

  2. Only (a) and (b)

  3. Only (b) and (c)

  4. All (a), (b) and (c)

  5. None of the above


Correct Option: E
Explanation:

None of the above s correct answer as all a,b,c are the differences between interface and abstract class.

Which of the following is/are the conditions for automatic type conversion? (a) The two types are compatible. (b) The destination type is lager than the source type. (c) The source type is lager than the destination type. When one type of data is assigned to another type of variable, an automatic type conversion takes place if some conditions are met.

  1. Only (a)

  2. Only (a) and (b)

  3. All (a), (b) and (c)

  4. Only (a) and (c)

  5. None of these


Correct Option: B
Explanation:

The two types are compatible. The destination type is lager than the source type. When these two conditions are met, a widening conversion takes place. For example, the int type is large enough to hold all valid byte values.

What will be the output of following program code? importjava.util.StringTokenizer; publicclassTokendemo { publicstaticvoid main(String[] args) {
StringTokenizerst=newStringTokenizer(Hi how are you?); while(st.hasMoreTokens()) {
System.out.println(st.nextToken()); } } }

  1. Hi how are you?

  2. Hihow are you ?

  3. Hihowareyou?

  4. Hihow are you?

  5. None of the above


Correct Option: B
Explanation:

Option 2 is correct answer using StringTkenizer class and println() method.

Which of the following specifies the creation of event handlers in certain situations?

  1. Abstract class

  2. Adapter class

  3. Interfaces

  4. All of the above

  5. None of the above


Correct Option: B
Explanation:

Java provides special feature called adapter class,that can specify the creation of event handlers in certain situations.

Which exception is thrown when user provides divisor as zero, i.e. c=a/b, where b=0?

  1. NullPointerException

  2. ArithmeticException

  3. IOException

  4. ArrayOutOfBoundsException

  5. IllegalAccessException


Correct Option: B
Explanation:

ArithmeticException gets raised whenever an invalid operation has been attempted by the user. For example, in the above expression, the division by zero exception is raised, if the user has provided the zero value for b.

How the further can inheritance be stopped?

  1. Using static modifier

  2. Using private access specifier

  3. Using final modifier

  4. Using volatile modifier

  5. None of these


Correct Option: C
Explanation:

Final modifier can be used with class, data member and methods. A class cannot be inherited when declared as final.

What will be the output of the following program code? publicclassSuperdenmo { publicstaticvoid main(String[] args) { B b=new B(); b.add(); b.display(); } } class A { intx,y; A() { x=10; y=20; } } class B extends A { intx,y,a,b; B() { x=100; y=200; } void add() { a=x+super.x;
b=y+super.y; } void display() { System.out.print(“value of a=”+a+nvalue of b=+b); } }

  1. value of a=110value of b=220

  2. value of a=10value of b=20

  3. value of a=100value of b=200

  4. value of a=100value of b=220

  5. none of the above


Correct Option: A
Explanation:

As super keyword is used to call constructor of parent class, the output of above program will bea=x+super.xb=y+super.ya=100+10=110b=200+20=220.

- Hide questions