Hide all answers
Hide all answers
View all answers
View all answers
Print
Try the Quiz
Learn Java programming through these flash cards. |
1. Given a package named EDU.Student, how would you import a class named Test contained in this package? Write one line statement.
Answer: import EDU.Student.Test; 2. Consider the following class definition: class Student { abstract double result( ) } This code will not compile since a keyword is missing in the first line. What is the keyword?
Answer: abstract 3. Consider the following class file: import java.awt.*; import java.io.*; package studentBase; class Test { void display( ) { System.out.println("RESULTS"); } } Will it compile? Yes or No. Give reason, if No.
Answer: No; The package definition must come first.
4. Consider the following code: class Product { public static void main(String args[ ]) { int x = 10, y = 20; System.out.println(mul(x, y)); } int mul(int a, int b) { return(a * b); } } Will it compile? Yes or No. Give reason, if No.
Answer: No; The static method is trying to invoke a non-static method. 5. Given below are two files: File Employee.java package purchase public class Employee { protected double age = 35.00; } File Company.java import purchase.Employee; public class Company { public static void main(String arg[ ]) { Employee e = new Employee( ); System.out.println("Age =" + e.age); } } Will it compile? Yes or No. Give reason, if No.
Answer: No; The field age in the Employee class should be public. 6. Consider the following code: class A { void method(int x) { System.out.println("x =" + x); } } class B extends A { void method(int y) { System.out.println("y =" + y); }
void method(String s) { System.out.println("s =" + s); } public static void main(String args[ ]) { A a1 = new A( ); A a2 = new B( ); a1.method(10); a2.method(20); } } What will be the output, when executed?
Answer: x = 10; y = 20 7. There are three classes that implement the DataInput and DataOutput interfaces. Two of them are DataInputStream and DataOutputStream. Which is the third one?
Answer: RandomAccessFile class 8. What output will the following program produce? class Bits { public static void main(String args[ ]) { short s1 = 3; // 0000 0011 short s2 = 13; // 0000 1101 s1 = (short) (s1 ^ s2); System.out.println("Result is " + s1); } }
Answer: Result is 14 9. State the output of the following program: class Condition { public static void main(String args[ ]) { int x = 10; int y = 15; System.out.println((x } }
Answer: Result = 3.0 10. Which of the classes in java.io package defines a method to delete a file?
Answer: File class 11. Given a valid File object reference, we can create a new file using two classes defined in java.io package. One is FileOutputStream class. Which is the other one?
Answer: RandomAccessFile class 12. If raf is an instance of RandomAccessFile, how can we move the file pointer to the end of the file? Write the statement.
Answer: raf.seek(raf.length((); 13. What will be the output of the following program when it is executed with the command line java Command Java is wonderful class Command { public static void main(String args[ ]) { for(int i = 1; i < args.length; i++) { System.out.print(args[i]); if( i != args.length ) System.out.print(" "); } System.out.println(" "); } }
Answer: is wonderful 14. What will be the output of the following code snippet when combined with suitable declarations and run? StringBuffer city = new StringBuffer("Madras"); StringBuffer string = new StringBuffer( ); string.append(new String(city)); string.insert(0, "Central "); String.out.println(string);
Answer: Central Madras 15. Consider the following program code: class Thread1 extends Thread { public void run( ) { System.out.println("Begin"); suspend( ); resume( ); System.out.println("End"); } } class ThreadTest { public static void main(String args[ ]) { Thread T1 = new Thread1( ); T1.start( ); } } On execution, what will be the output?
Answer: Begin
Try the Quiz : Java Programming : Flash Cards II
|