Java Programming Questions & Answers: part7



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

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

6.class MyClass { public static void main(String[] args) { int k = 0; int l = 0; for (int i=0;i<=3;i++) { k++; if (i==2) break; l++; } System.out.println(k+", "+l); } }

The program will fail to compile
The program will print 3, 3 when run
The program will print 4, 3 when run if break is replaced by continue
The program will fail to compile if break is replaced by return
The program will fail to compile if break is simply removed.

7.How restrictive is the default accessibility compared to public, protected, and private accessibility?

Less restrictive than public
More restrictive than public, but less restrictive than protected
More restrictive than protected, but less restrictive than private
More restrictive than private
Less restrictive than protected from within a package, and more restrictive than protected from outside a package.

8.Given the following definition of a class, which fields are accessible from outside the package com.corporation.project? package com.corporation.project; public class MyClass { int i; public int j; protected int k; private int l; } Select the correct answer.

Field i is accessible in all classes in other packages
Field j is accessible in all classes in other packages
Field k is accessible in all classes in other packages
Field l is accessible in all classes in other packages
Field l is accessible in subclasses only in other packages.

9.Given the following member declarations, which statement is true? int a; //(1) static int a; //(2) int f() { return a; } //(3) static int f() { return a; } //(4)

Declarations (1) and (3) cannot occur in the same class definition
Declarations (2) and (4) cannot occur in the same class definition
Declarations (1) and (4) cannot occur in the same class definition
Declarations (2) and (3) cannot occur in the same class definition
None of the above.

10.Which one of the following class definitions is a valid definition of a class that cannot be extended? #96. Which one of the following class definitions is a valid definition of a class that cannot be extended?

class Link { }
abstract class Link { }
native class Link { }
static class Link { }
final class Link { }.

More Java Programming QUESTIONS AND ANSWERS available in next pages

    Health is the greatest gift, contentment is the greatest wealth -Buddha
Identify your problems but give your power and energy to solutions- Tony Robbins