Basics of Java
Java is a programming language. The objective questions include programs and other object-oriented technology concepts.
Questions
Which of the following is not an access specifier?
- Private
- Static
- Public
- Protected
- None of the above
Which type of inheritance is not possible/allowed in Java using extends keyword?
- Multiple
- Multilevel
- Single
- Hierarchical
- None of the above
________ modifier is often used in multithreaded programs.
- Native
- Static
- Syncronized
- Final
- None of the above
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.
- Only (a)
- Only (a) and (b)
- Only (b) and (c)
- All (a), (b) and (c)
- None of the above
Which of the following cannot generate an event?
- TextArea
- TextField
- Label
- Buttons
- None of the above
Which of the following keywords is not present in Java?
- goto
- break
- continue
- all of the above
- none of these
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
- Only (a) and (d)
- Only (e)
- Only (b) and (c)
- None of the above
- All of the above
Which of the following features present in C/C++ is not supported by Java?
- Inheritance
- Function overloading
- Pointer
- Arrays
- None of the above
To which class does the method to UpperCase() belong?
- String class
- Char class
- Math class
- String buffer class
- None of the above
What is the output of a Java compiler?
- Executable code
- Bytecode
- Bitcode
- Assembly language code
- None of these
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);
}
}
}
- WWEWELWELCWELCOWELCOMWELCOM
- WELCOMEWELCOMWELCOWELCWELWEW
- W WE WEL WELC WELCO WELCOM WELCOME
- WELCOME
- None of the above
What is the use of Super keyword in Java?
- Used for inheritance
- Allows child class to call parameterized constructor of the class
- Used for making a function inline
- Used for making class or function template
- Allows parent class to call parameterized constructor of child 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);
}
}
- Separates digits and reverses the number
- Reverses the number
- Addition of digits of the given input number
- All of the above
- None of the above
What is the difference between == and equals()?
- Both == and equals() check whether two objects belong to the same instance.
- == compares characters inside a string object, while equals() check whether two objects belong to the same instance.
- Both == and equals() compare characters inside the string object.
- == operator checks whether two objects belong to the same instance, while equals() compares characters inside the string object.
- None of the above
Which of the following accesses is/are provided by RandomAccessFile class?
- r, rw
- rws, rwd
- only rw
- r, rw, rws, rwd
- none of the above
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
- checks whether the two strings are equal or not
- reverses the string
- check whether the string is palindrome or not
- compares the StringBuffer and String object
- none of the above
Which of the following is/are not the built in exception(s) in Java?
(a) ArrayIndexOutOfBoundsException
(b) NullPointerException
(c) Arithmetic Exception
(d) IOException
- Only (a)
- Only (a) , (b), (c)
- Only (a) and (b)
- All (a), (b), (c), (d) are built in exceptions.
- None of the above
Which of the following is not a built in class in Java?
- String class
- Math class
- Applet class
- Util class
- StringBuffer class
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.
- Only (a)
- Only (a) and (b)
- Only (b) and (c)
- All (a), (b) and (c)
- None of the above
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.
- Only (a)
- Only (a) and (b)
- All (a), (b) and (c)
- Only (a) and (c)
- None of these
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());
}
}
}
- Hi how are you?
- Hihow are you ?
- Hihowareyou?
- Hihow are you?
- None of the above
Which of the following specifies the creation of event handlers in certain situations?
- Abstract class
- Adapter class
- Interfaces
- All of the above
- None of the above
Which exception is thrown when user provides divisor as zero, i.e. c=a/b, where b=0?
- NullPointerException
- ArithmeticException
- IOException
- ArrayOutOfBoundsException
- IllegalAccessException
How the further can inheritance be stopped?
- Using static modifier
- Using private access specifier
- Using final modifier
- Using volatile modifier
- None of these
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);
}
}
- value of a=110value of b=220
- value of a=10value of b=20
- value of a=100value of b=200
- value of a=100value of b=220
- none of the above