Font size
WorksheetsPRELIMINARY EXAMINATION [OOP]
Total questions: 85
Worksheet time: 52mins
Describe method.
A component of a program in a big program.
A program to perform a specific task.
A component of a program written to perform a specific task.
A variable that use to read an input.
There two (2) types of method which are
return
Standard library
User defined
non-return
This is a general structure a method.
<Returnvalue type> <Method Name> (argument / s)
<Modifier> < type> <Method Name> (parameter / s)
public static void main (String[ ] args)
<Method Name> (parameter)
This is an example of a non-return method.
True
False
In which line is representing the meaning of Standard library method.
Line 2
Line 8
Line 13
Line 10
Identify the line with syntax error.
Line 8 and Line 15
Line 10 only
Line 6, Line 8, Line 10
Line 8, Line 11 and Line 15
The name of this method is ....
Oddsum
int Oddsum
int Oddsum (int number)
return totaloddsum
Data type for non return method is
int
double
void
public static
Fix the syntax error in Line 8.
Cylinder sc = new System.in( );
Scanner sc = new Scanner (System.in);
Cylinder Volume = new Volume( );
Cylinder call = new Cylinder( );
Fix all the syntax error. Your answer may more than 1.
Circle mtd = new Circle ( );
r=sc.nextInt( );
void Area (double r);
double r;
1. Which of this method is given parameter via command line arguments?
a) main()
b) recursive() method
c) Any method
d) System defined methods
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
A and B
D) None of the above
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
What will be the Output of the below code:
public class Demo{
public static void main(String[] arr){
}
public static void main(String arr){
}
}
a) Nothing
b) Error
C) Finite
d) Hii
char is 2 byte in storage?
True
False
Name the data type: '3'
int
char
String
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
class exception_handling
{ public static void main(String args[])
{ try
{ int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e)
{ System.out.print("B");
}
finally
{ System.out.print("C");
}
}
}
A
B
AC
BC
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What method do you use to read a string input from the user using Scanner?
nextLine()
readLine()
readString()
inputString()
Which method is used to read an integer input from the user using Scanner?
nextInt()
readInt()
inputInt()
getInt()
What happens if you try to read an integer using nextInt() but the input is not an integer?
It throws a NoSuchElementException
It returns 0
It throws an InputMismatchException
It returns -1
How do you close a Scanner object in Java?
scanner.close();
close(scanner);
Scanner.close();
scanner.exit();
What is the correct syntax to output "HelloWorld" in Java?
(a)
