WizIQ helps you learn and teach online - any subject you can think of!
Join for FREE

Fundamentals of Core Java, Arrays,Command Line Arguements online Test

Which statement is true?
An anonymous inner class may be declared as final
An anonymous inner class can be declared as private
An anonymous inner class can implement multiple interfaces
An anonymous inner class can access final variables in any enclosing scope
Which declaration prevents creating a subclass of an outer class?
static class FooBar{}
private class FooBar{}
abstract public class FooBar{}
Final public class FooBar{}
Given: 1. byte [] arry1, array2[]; 2. byte array3 [][]; 3. byte[][] array4; If each array has been initialized, which statement will cause a compiler error?
array2 = array1;
array2 = array3;
array2 = array4;
both B and C
public class returnIt ( 2. returnType methodA(byte x, double y) ( 3. return (short) x/y * 2; 4. ) 5. ) What is the valid returnType for methodA in line 2?
long
short
float
double
import java.awt*; 2. 3. public class X extends Frame ( 4. public static void main(string []args) ( 5. X x = new X (); 6. X.pack(); 7. x.setVisible(true); 8. ) 9. 10. public X () ( 11. setlayout (new GridLayout (2,2)); 12. 13. Panel p1 = new panel(); 14. Add(p1); 15. Button b1= new Button (“One”); 16. P1.add(b1); 17. 18. Panel p2 = new panel(); 19. Add(p2); 20. Button b2= new Button (“Two”); 21. P2.add(b2); 22. 23. Button b3= new Button (“Three”); 24. add(b3); 25. 26. Button b4= new Button (“Four”); 27. add(b4); 28. ) 29. ) Which two statements are true? (Choose Two) A. All the buttons change height if the frame height is resized. B. All the buttons change width if the Frame width is resized. C. The size of the button labeled “One” is constant even if the Frame is resized. D. Both width and height of the button labeled “Three” might change if the Frame is resized.
A,B
C,D
A,D
B,C
What writes the text “” to the end of the file “file.txt”?
OutputStream out= new FileOutputStream (“file.txt”); Out.writeBytes (“/n”);
OutputStream os= new FileOutputStream (“file.txt”, true); DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);
OutputStream os= new FileOutputStream (“file.txt”); DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);
OutputStream os= new OutputStream (“file.txt”, true); DataOutputStream out = new DataOutputStream(os); out.writeBytes (“/n”);
------------------------(from the Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation.
Encapsulation
polymorphism
Information hiding
Inheritance
class Example2 { public static void main(String args[]) { int num; // this declares a variable called num num = 100; // this assigns num the value 100 System.out.println("This is num: " + num); num = num * 2; System.out.print("The value of num * 2 is "); System.out.println(num); } } When you run this program, what will be the output?
This is num: 100 The value of num * 2 is 200
This is num: 10 The value of num * 2 is 20
This is num: 1000 The value of num * 2 is 2000
This is num: 1 The value of num * 2 is 2
*/ class ForTest { public static void main(String args[]) { int x; for(x = 0; x<10; x = x+1) System.out.println("This is x: " + x); } } This program generates the following output: This is x: 0 This is x: 1 This is x: 2 This is x: 3 This is x: 4 This is x: 5 This is x: 6 This is x: 7 This is x: 8 This is x: 9 In this example, what is x in the above program?
x is the loop control variable
x is a predefined variable
x is a constant
x is a label
class Average { public static void main(String args[]) { double nums[] = {10.1, 11.2, 12.3, 13.4, 14.5}; double result = 0; int i; for(i=0; i<5; i++) result = result + nums[i]; System.out.println("Average is " + result / 5); } } What is the out put of the above program?
12.3
13.2
14.5
None of the above
Demonstrate a two-dimensional array. class TwoDArray { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } } What is the out put generated by the above program ?
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
None of the above
Demonstrate the % operator. class Modulus { public static void main(String args[]) { int x = 42; double y = 42.25; System.out.println("x mod 10 = " + x % 10); System.out.println("y mod 10 = " + y % 10); } } When you run this program what will be the out put of the program?
x mod 10 = .2 y mod 10 = 22.5
x mod 10 = 2 y mod 10 = 2.25
x mod 10 = 2.5 y mod 10 = 2.25
x mod 10 = 2 y mod 10 = 22.5
Unsigned shifting a byte value. class ByteUShift { static public void main(String args[]) { char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; byte b = (byte) 0xf1; byte c = (byte) (b >> 4); byte d = (byte) (b >>> 4); byte e = (byte) ((b & 0xff) >> 4); System.out.println(" b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]); System.out.println(" b >> 4 = 0x" + hex[(c >> 4) & 0x0f] + hex[c & 0x0f]); System.out.println(" b >>> 4 = 0x" + hex[(d >> 4) & 0x0f] + hex[d & 0x0f]); System.out.println("(b & 0xff) >> 4 = 0x" + hex[(e >> 4) & 0x0f] + hex[e & 0x0f]); } }
b = 0xf1 b >> 4 = 0xff b >>> 4 = 0xff (b & 0xff) >> 4 = 0x
b = 0xf1 b >> 4 = 0xff b >>> 4 = 0xff (b & 0xff) >> 4 = 0x0f
( ) [ ] . ++ – – ~ ! * / % + – >> >>> << > >= < <= == != & ^ | && || ?: = op= In the above operators which is having highest priority?
( ) [ ] .
= op=
( ) [ ] . and = op=
None of the above
LANGUAGE // Demonstrate return. class Return { public static void main(String args[]) { boolean t = true; System.out.println("Before the return."); if(t) return; // return to caller System.out.println("This won't execute."); } } The output from this program is shown here: Before the return.A LANGUAGE
Before the return.
This won't execute
Before the return & This won't execute
None of the above
LANGUAGE /* A program that uses the Box class. Call this file BoxDemo.java */ class Box { double width; double height; double depth; } // This class declares an object of type Box. class BoxDemo { public static void main(String args[]) { Box mybox = new Box(); double vol; // assign values to mybox's instance variables mybox.width = 10; mybox.height = 20; mybox.depth = 15; // compute volume of box vol = mybox.width * mybox.height * mybox.depth; System.out.println("Volume is " + vol); } } what is the out put of the above program ?Wwhat JAVANGUAGE
Volume is 300.0
Volume is 3000.0
Volume is 30000.0
Volume is 30.0
// Returning an object. class Test { int a; Test(int i) { a = i; } Test incrByTen() { Test temp = new Test(a+10); return temp; } } class RetOb { public static void main(String args[]) { Test ob1 = new Test(2); Test ob2; ob2 = ob1.incrByTen(); System.out.println("ob1.a: " + ob1.a); System.out.println("ob2.a: " + ob2.a); ob2 = ob2.incrByTen(); System.out.println("ob2.a after second increase: " + ob2.a); } } The output generated by this program is shown here: ob1.a: 2 ob2.a: 12 ob2.a after second increase: 22 what is the out put of the above program ?
ob1.a: 2 ob2.a: 12 ob2.a after second increase: 22
ob1.a: 22 ob2.a: 12 ob2.a after second increase: 22
ob1.a: 2 ob2.a: 120 ob2.a after second increase: 22
LANGAGE A simple example of recursion. class Factorial { // this is a recursive function int fact(int n) { int result; if(n==1) return 1; result = fact(n-1) * n; return result; } } class Recursion { public static void main(String args[]) { Factorial f = new Factorial(); System.out.println("Factorial of 3 is " + f.fact(3)); System.out.println("Factorial of 4 is " + f.fact(4)); System.out.println("Factorial of 5 is " + f.fact(5)); } }
Factorial of 3 is 6 Factorial of 4 is 24 Factorial of 5 is 128
Factorial of 3 is 6 Factorial of 4 is 24 Factorial of 5 is 120
Factorial of 3 is 9 Factorial of 4 is 16 Factorial of 5 is 125
None of the above
Demonstrate String arrays. class StringDemo3 { public static void main(String args[]) { String str[] = { "one", "two", "three" }; for(int i=0; i str[0]: one str[1]: two str[2]: three
str[1]: one str[2]: two str[3]: three
str[0]: two str[1]: three str[2]: four
None of the above
Display all command-line arguments. class CommandLine { public static void main(String args[]) { for(int i=0; i args[1]: this args[2]: is args[3]: a args[4]: test args[5]: 100 args[6]: -1
args[0]: this args[1]: is args[2]: a args[3]: test args[4]: 100 args[5]: -1
args[0]: -1 args[1]: is args[2]: a args[3]: test args[4]: 100 args[5]: this
None of the above
Description:

This Test contains 20 questions and it will check your Knowledge on the Arrays,Command line arguments and Classes & Objects.
Disclaimer: Content, such as images used in the questions (if any), have been picked up from various places for the sole purpose of Instruction.

Comments
poorna chandar rao
By: poorna chandar rao
753 days 10 hours 17 minutes ago

i would like to learnig java please coperative with

suganya
By: suganya
677 days 16 hours 34 minutes ago

take a test

manoj
By: manoj
535 days 14 hours 10 minutes ago

15 th answer is wrong i think...pls check...

manoj
By: deepthi24
111 days 19 hours 57 minutes ago

yes it is ....

a
By: a
243 days 17 hours 20 minutes ago

where do i get more practice tests on core java plz report

hitesh
By: hitesh
237 days 10 hours 14 minutes ago

Q15.correct answer should be (a).

Narasimharao P
By: Narasimharao P
203 days 17 hours 34 minutes ago

15.Q answer is (a)

PRATEEK
By: PRATEEK
187 days 14 hours 15 minutes ago

test is good comprises of nice ques only 15th one is doubtful....

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no.:


Area code Number
Subject you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy

Your Facebook Friends on WizIQ

More Tests By Author

ASP Server Controls
10 Questions | 227 Attempts

ASP.NET, Namespaces ASP.NET
10 Questions | 855 Attempts

An ASP.NET Application
10 Questions | 173 Attempts

Test your basic knowledge on DATASTRUCTURES, STACK
10 Questions | 410 Attempts