Java Programming
A Test to check the Programming Concepts in Java
Questions
If m = -16 and n = -5 (m and n are int types), the result of the expression m%n is
- -1
- 1
- -3
- 3
Which of the following is not supported by Java?
- Polymorphism
- Inheritance
- Message communication
- Operator overloading
Consider the following code:
If(num<=0) If(num<0) System.out.println(“Number is negative”) Else System.out.ptintln(“Number is positive”); If num=0, then output will become
- 0
- negative
- positive
- none of these
A variable declared inside the for loop control cannot be referenced outside the loop
- true
- false
How can the under given statement be written?If (p<100) Flag = 10; Else Flag = 20;
- flag=(p<100) ? 10 : 20;
- flag=(p<100) : 10 ? 20 ;
- flag=(p<100) : 20 ? 10 ;
- flag=(p<100) ? 20 : 10;
Objects cannot be passed to a method by use of call-by reference
- true
- false
Every try statement should be followed by at least one catch statement
- true
- false
_________ must be the first statement of Java source file (except comment statements).
- Class
- Package
- Interface
- Main method
The method s1.compareTo(s2) returns
- True if s1 < s2
- Negative if s1<s2, positive if s1>s2 and zero if s1=s2
- Zero if s1=s2
- Positive if s1 > s2
What is wrong with the following code?
Switch(x) {Case 1: num1 = 100; num2 = 200; Case 2: num3 = 300: Break; num4 = 400;}
- Nothing is wrong
- Break is not used in case 2
- Default is not there
- Num4 = 400 is not reachable
What is AWT?
- Abstract Window Toolkit
- Active Window Terminal
- Abstract Window Terminal
- Active Window Toolkit
Which one of the following is not in Java.lang package?
- Arithmetic Exception
- Array Store Exception
- Float
- Math
When we implement interface method it should be declared as public.
- true
- false
Any method in a superclass can be overridden in its subclass.
- true
- false
Give the output of the following: int n=10; while (true) {if (n<5) continue; n=n-2;} System.out.println(n);
- 5
- 10
- 2
- Infinite loop
What is Hot Java?
- Web browser from Sun Microsystem
- HTML Editor
- Java Editor
- Java Compiler
How many times will the body of the following loop execute? nt m = 10,n = 7; while(m%n>0) {… m = m+1; n = n + 2; …. }
- 4
- 3
- 0
- Infinite
Which of the following must be used to get 32, if the value of x is 32.9?
- Ceil(x)
- Round(x)
- Floor(x)
- Abs(x)
Throwing an expression always results in termination of the program.
- true
- false
- Depends on the exception.
- None
Use _________ option if the field is to be visible everywhere in the current package only.
- private
- public
- default
- protected
Declaring a class ______ prevents any unwanted extensions to the class.
- close
- terminate
- end
- final
Which of the following options is not an array declaration?
- float[ ] marks
- number = new int[5]
- int product [ ] [ ]
- float num{ }
Interfaces are used as _________, whose properties are inherited by classes.
- sub-classes
- super classes
- extended classes
- none of the above
Which one of the following is/are not used to suspend the thread temporarily?
- sleep()
- suspend()
- wait()
- all of the above
Which of the following statements are true?
i. An abstract class may not have any final methods.
ii. A final class may not have any abstract methods.
iii. An inner class may be declared with any accessibility keyword.
iv. Transient variables must be static.
- ii & iii
- i & ii
- i & iv
- iii & iv