Java Programming Questions & Answers: part18



Software Programming : Java Programming QUESTIONS AND ANSWERS :: part18 : 6 to 10

Following Software Programming language Entrance Multiple choice objective type questions and answers will help you in Software Programming 2024 examinations :

6.Given the code below: class A { public void print() { System.out.println("hi"); } } class B extends A { public void print() { System.out.println("bye"); } } What does each of the following code samples do: A a = new B(); a.print();

Prints nothing
Prints “hi”
Prints “bye”
The code does not compile, the compiler returns a type error
The code throws a runtime exception.

7.What is the output of the following code? class Arithmetic { public static void main (string args[]) { int x=17, y=5; System.out.println(“x =” +x); System.out.println(“y =” +y); System.out.println(“x+y=” +(x+y)); System.out.println(“x-y=” +(x-y)); System.out.println(“x*y=” +(x*y)); System.out.println(“x/y=” +(x/y)); System.out.println(“x%y=” +(x%y)); } }

5, 17, 12, 85, 3, 2
17, 5, 22, 12, 85, 3, 2
17, 5, 20, 21, 85, 3, 2
2, 3, 85, 12, 22, 5, 17
17, 5, 12, 22, 85, 2, 3.

8.Suppose we now wish to print the balance information for an account with the following code: Account myAccount = new OverdraftAccount(5, 10); myAccount.printBalance(); Which of the following statement is true?

The printed output is the string “Account”
The printed output is the string “OverdraftAccount”
The printed output is the string “Account: $5”
The printed output is the string “OverdraftAccount: $5”
There will be a compilation error because OverdraftAccount, the run-time type of myAccount, does not define the printBalance() method.

9.class Relational{ public static void main (string args[]) { int x=7, y=11, z=11; System.out.println(“y<=z =” +(y<=z)); } }

y<=z = 0
y<=z = 1
y<=z = true
y<=z = false
y

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
The only place where success comes before work is in the dictionary.- Vidal Sassoon