Java Programming-1

$7.50

SKU: AMSEQ-146 Category:

Assignment – A

 

Q1)

a) What is Object Orientation? Explain the advantages of Object Orientation.

b) Explain the different application of Java Programming Language

 

Q2)

a) What is break and continue in Java? Write a program to explain the uses of these break and continue in java.

b) Explain why main method in java is always static & public.

c) Explain the use of final in Java with Example.

 

 

Q3) What is a Constructor? Explain the need of Constructors overloading in java Program.

 

 

Q4) Write a program to print the following output using the for loop.

1

2 2

3 3 3

4 4 4 4

5 5 5 5

 

Q5) What is interface in java? Write a program in Java to explain interface and multiple inheritance.

 

Assignment – B

 

Q1) What is exception? Explain how exceptions are handled in Java. What are different types of exceptions in java?

 

Q2) What is Multithreading? Explain different ways of implementation of multithreading in java.

 

Q3) What is Applet. Explain Applet Life Cycle.

 

Q4) Write a Java program that calculates and prints the simple interest using the formula :

Simple Interest = PNR / 100

Input values P,N,R should be accepted as command line input as below.

e.g. java Simple Interest 5 10 1

 

 

Assignment – C

 

Q1. Consider the following program:

import myLibrary.*;

public class ShowSomeClass

{

// code for the class…

}

 

What is the name of the java file containing this program?

A. myLibrary.java

B. ShowSomeClass.java

C. ShowSomeClass

D. ShowSomeClass.class

E. Any file name with the java suffix will do

 

 

Q2. Consider the following code snippet

String river = new String(“Columbia”);

System.out.println(river.length());

 

What is printed?

A. 6

B. 7

C. 8

D. Columbia

E. river

 

Q3. A constructor

A. must have the same name as the class it is declared within.

B. is used to create objects.

C. may be declared private

D. A and B

E. A, B and C

 

Q4. Which of the following may be part of a class definition?

A. instance variables

B. instance methods

C. constructors

D. all of the above

E. none of the above

 

 

 

 

 

Q5.What is different between a Java applet and a Java application?

A. An application can in general be trusted whereas an applet can’t.

B. An applet must be executed in a browser environment.

C. An applet is not able to access the files of the computer it runs on

D. (A), (B) and (C).

E. None of the above

 

Q6.What will be the output of the program?

public class Foo

{

public static void main(String[] args)

{

try

{

return;

}

finally

{

System.out.println( “Finally” );

}

}

}

A. Finally

B. Compilation fails.

C. The code runs with no output.

D. An exception is thrown at runtime.

 

Q7.What is the name of the method used to start a thread execution?

A. init();

B. start();

C. run();

D. resume();

 

Q8.Which two of the following methods are defined in class Thread?

1. start()

2. wait()

3. notify()

4. run()

5. terminate()

 

A. 1 and 4 B. 2 and 3

C. 3 and 4 D. 2 and 4

 

Q9. Which will contain the body of the thread?

A. run(); B. start();

C. stop(); D. main();

 

 

Q10. Which is a valid declaration of a String?

A. String s1 = null;

B. String s2 = ‘null’;

C. String s3 = (String) ‘abc’;

D. String s4 = (String) ‘ufeed’;

 

Q11. Which is the valid declarations within an interface definition?

A. public double methoda();

B. public final double methoda();

C. static void methoda(double d1);

D. protected void methoda(double d1);

 

Q12.Which one of the following will declare an array and initialize it with five numbers?

A. Array a = new Array(5);

B. int [] a = {23,22,21,20,19};

C. int a [] = new int[5];

D. int [5] array;

 

 

Q13.Which is a reserved word in the Java programming language?

A. method

B. native

C. subclasses

D. reference

E. array

 

Q14. Which is a valid keyword in java?

A. interface

B. string

C. Float

D. unsigned

 

Q15.What will be the output of the program?

public class X

{

public static void main(String [] args)

{

try

{

badMethod();

System.out.print(“A”);

}

catch (Exception ex)

{

System.out.print(“B”);

}

finally

{

System.out.print(“C”);

}

System.out.print(“D”);

}

public static void badMethod()

{

throw new Error(); /* Line 22 */

} }

A. ABCD

B. Compilation fails.

C. C is printed before exiting with an error message.

D. BC is printed before exiting with an error message.

 

Q16. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

A. public

B. private

C. protected

D. transient

 

Q17. public class Test { }

What is the prototype of the default constructor?

A. Test( )

B. Test(void)

C. public Test( )

D. public Test(void)

 

Q18. What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?

A. public

B. abstract

C. protected

D. synchronized

E. default access

 

Q19. You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?

A. public

B. private

C. protected

D. default access

 

 

Q20. Given:

int x = 12;

while (x < 10) {

x–;

}

System.out.print(x);

What is the result?

A. 0

B. 10

C. 12

D. Line 29 will never be reached.

 

Q21 Given:

public static void main(String[] args) {

Object obj = new int[] { 1, 2, 3 };

int[] someArray = (int[])obj;

for (int i : someArray) System.out.print(i + ” “);

}

What is the result?

A. 1 2 3

B. Compilation fails because of an error in line 12.

C. Compilation fails because of an error in line 13.

D. Compilation fails because of an error in line 14.

E. A ClassCastException is thrown at runtime.

 

Q22 Given:

public static void main(String[] args) {

for (int i = 0; i <= 10; i++) {

if (i > 6) break;

}

System.out.println(i);

}

What is the result?

A. 6

B. 7

C. 10

D. 11

E. Compilation fails.

F. An exception is thrown at runtime.

 

Q:23 Given:

public static void main(String[] args) {

Integer i = new Integer(1) + new Integer(2);

switch(i) {

case 3: System.out.println(“three”); break;

default: System.out.println(“other”); break;

} }

What is the result?

A. three

B. other

C. An exception is thrown at runtime.

D. Compilation fails because of an error on line 12.

E. Compilation fails because of an error on line 13.

F. Compilation fails because of an error on line 15.

 

 

Q24. Which of the following is TRUE?

A. In java, an instance field declared public generates a compilation error.

B. int is the name of a class available in the package java.lang

C. Instance variable names may only contain letters and digits.

D. A class has always a constructor (possibly automatically supplied by the java compiler).

E. The more comments in a program, the faster the program run

 

 

Q25.Which of the following may be part of a class definition?

A. instance variables

B. instance methods

C. constructors

D. all of the above

E. none of the above

 

Q26. What will be the output of the program?

class PassA

{

public static void main(String [] args)

{

PassA p = new PassA();

p.start();

}

 

void start()

{

long [] a1 = {3,4,5};

long [] a2 = fix(a1);

System.out.print(a1[0] + a1[1] + a1[2] + ” “);

System.out.println(a2[0] + a2[1] + a2[2]);

}

 

long [] fix(long [] a3)

{

a3[1] = 7;

return a3;

}

}

A.12 15

B.15 15

C. 3 4 5 3 7 5

D. 3 7 5 3 7 5

 

Q27. What will be the values of x, m, and n after execution of the following statements?

int x, m, n;

m = 10;

n = 15;

x = ++m + n++;

 

A. x = 25, m = 10, n = 15 B. x = 27, m = 10, n = 15

C. x = 26, m = 11, n = 16 D. x = 27, m = 11, n = 16

 

Q28.If m and n are int type variables, what will be the result of the expression

m % n

when m = 5 and n = 2?

A. 0

B. 1

C. 2

D. None of the above

 

Q29. Consider the following class defi nitions:

class maths

{

Student student1;

}

class Student

{

String name;

}

This code represents:

A. an ‘is a’ relationship

B. a ‘has a’ relationship

C. both

D. neither

Q30.Which of the following statements are true?

1. We cannot use abstract classes to instantiate objects directly.

2. The abstract methods of an abstract class must be defi ned in its subclass.

3. We cannot declare abstract constructors.

4. We may declare abstract static methods.

 

A. Line 1 only

B. Line 2 only

C. Line 1 and line 2 only

D. Line 1, line 2 and line 3 only

E. All are true

 

Q31.Which keyword can protect a class in a package from accessibility by

the classes outside the package?

A. private

B. protected

C. final

D. don’t use any keyword at all (make it default)

 

Q32. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?

A. private

B. protected

C. public

D. private protected

 

Q33.The use of protected keyword to a member in a class will restrict its visibility as follows:

A. Visible only in the class and its subclass in the same package.

B. Visible only inside the same package.

C. Visible in all classes in the same package and subclasses in other packages

D. Visible only in the class where it is declared.

 

Q34. A package is a collection of

A. classes

B. interfaces

C. editing tools

D. classes and interfaces

 

Q35. Which of the following defines a legal abstract class?

A. class Vehicle {

abstract void display( ); }

B. abstract Vehicle {

abstract void display( ); }

C. abstract class Vehicle {

abstract void display( ); }

D. class abstract Vehicle {

abstract void display( ); }

E. abstract class Vehicle {

abstract void display( ); {

System.out.println(“Car”); }}

 

Q36. Which of the following methods belong to the String class?

A. length( )

B. compareTo( )

C. equals( )

D. substring( )

E. All of them

 

Q37.Given the code

String s1 = “yes”;

String s2 = “yes”;

String s3 = new String (s1) ;

Which three of the following would equate to true?

A. s1 = = s2

B. s1 = s2

C. s3 = = s1

D. s1.equals(s2)

E. s3.equals(s1)

 

Q38.The methods wait( ) and notify( ) are defi ned in

A. java.lang.String

B. java.lang.Runnable

C. java.lang.Object

D. java.lang.Thread

E. java.lang.ThreadGroup

 

Q39.When we invoke repaint( ) for a Component, the AWT invokes the method:

A. draw( )

B. show( )

C. update( )

D. paint( )

 

Q40.Which of the following methods can be used to remove a component from the display?

A. delete( )

B. remove( )

C. disappear( )

D. hide( )

E. move( )

Reviews

There are no reviews yet.

Be the first to review “Java Programming-1”

Your email address will not be published. Required fields are marked *

PlaceholderJava Programming-1
$7.50