Java Programming Questions and Answers Set 22

Java Programming OOPs

Questions 211 to 220



211.
Which of the following is/are valid comment(s) in java?
(a)
/** comment */
(b)
/* comment */
(c)
/* comment
(d)
// comment
(e)
Both (a) and (b).
212.
What is the correct signature of the main method?
(a)
public static  main(String[] args)
(b)
public static void main(String[] args)
(c)
public static void main(String[] )
(d)
public static void main(String  args)
(e)
public void main(String[] args).
213.
Which of the following is not a valid statement?
(a)
Instance methods can access instance variables and instance methods directly
(b)
Instance methods can access class variables and class methods directly
(c)
Class methods can access class variables and class methods directly
(d)
Class methods can access instance variables or instance methods directly
(e)
Class methods cannot use ‘this’ keyword as there is no instance for this to refer to.
214.
What is the correct order of defining a Class?
1.    The name of the class's parent (super class), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
2.    The class name, with the initial letter capitalized by convention.
3.    Modifiers such as public, private, and a number of others that you will encounter later.
4.    The class body, surrounded by braces, {}.
5.    A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
(a)
3,1,2,5,4
(b)
1,2,3,5,4
(c)
3,2,1,5,4
(d)
5,1,2,3,4
(e)
5,4,3,2,1.
215.
public class PassPrimitiveByValue {
public static void main(String[] args) {     
int x = 3;     
//invoke passMethod() with x as argument
passMethod(x);
// print x to see if its value has changed
System.out.println("After invoking passMethod, x = " + x);     
}
// change parameter in passMethod()
public static void passMethod(int p) {
p = 10;
}
}
What is the output of the above program?
(a)
10
(b)
3
(c)
garbage value
(d)
4
(e)
10.3.
216.
What is the output of the following code?
IdentifyMyParts a = new IdentifyMyParts();
IdentifyMyParts b = new IdentifyMyParts();
a.y = 5;
b.y = 6;
IdentifyMyParts.x = 1;
b.x = 2;
System.out.println("a.y = " + a.y);
System.out.println("b.y = " + b.y);
System.out.println("IdentifyMyParts.x = " + a.x);
System.out.println("b.x = " + b.x);
(a)
a.y = 5
b.y = 6
a.x = 2
b.x = 2
(b)
a.y = 5
b.y = 5
a.x = 2
b.x = 2
(c)
a.y = 5
b.y = 6
a.x = 3
b.x = 2
(d)
a.y = 5
b.y = 6
a.x = 2
b.x = 3
(e)
a.y = 6
b.y = 6
a.x = 2
b.x = 2.
217.
Which of the following is legal valid variable name?
(a)
1num
(b)
#twenty
(c)
@one
(d)
timeOfDay
(e)
temp val.
218.
What is the bit size of int in java?
(a)
8
(b)
16
(c)
32
(d)
64
(e)
128.
219.
Which one of these is a valid constructor declaration for the class named student?
(a)
Student(student  b) { }
(b)
Student  Student() { }
(c)
private final  Student[] { }
(d)
void Student() { }
(e)
abstract student() { }.
220.
Which access specifiers should be implemented in a class for all interface methods?
I.     Private.
II.     Public.
III.    Protected.
(a)
Only (I) above
(b)
Only (II) above
(c)
Only (III) above
(d)
Both (I) and (III) above
(e)
All (I), (II) and (III) above.


Answers


211.
Answer : (c)
Reason:  The Java programming language supports three kinds of comments:
/* text */
The compiler ignores everything from /* to */.
/** documentation */
This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */.
// text
The compiler ignores everything from // to the end of the line.
212.
Answer : (b)
Reason:  The correct signature is public static void main(String[] args)
213.
Answer : (d)
Reason:  Class methods cannot access instance variables or instance methods directly—they must use an object reference.
214.
Answer : (c)
Reason:  class declarations can include these components, in order:
1.    Modifiers such as public, private, and a number of others that you will encounter later.
2.    The class name, with the initial letter capitalized by convention.
3.    The name of the class's parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.
4.    A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
The class body, surrounded by braces, {}.
215.
Answer : (b)
Reason:  Primitive arguments, such as an int or a double, are passed into methods by value. This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost.So the output is 3 only.
216.
Answer : (a)
Reason:  Remaining all are contradictory.
217.
Answer : (d)
Reason:  Can only Start with a Letter, Underscore (_) , or Dollar Sign ($).After the first letter Name can include any letter or Number but cannot include Symbols such as %, @, *  and so on.
218.
Answer : (c)
Reason:  The bit size of int is 32.
219.
Answer : (a)
Reason:  A constructor cannot specify any return type, not even void. A constructor cannot be final, static or abstract.
220.
Answer : (b)
Reason:  Interfaces are abstraction of functionality that can be implemented in more than one way when required. The abstraction must be made available as public for the use by other parts of the program.


<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


13 comments :

  1. Q 211. Which of the following is/are valid comment(s) in java?

    It should be "Which of the following is/are INVALID comment(s) in java?"

    ReplyDelete
  2. This is a great article.I am y much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

    java examples

    ReplyDelete
  3. Nice article.you have shared nice post.
    visit java batch processing example
    click here

    ReplyDelete
  4. good pick up lines
    Sign Up into EnjoyXoxo, It is the clever and good pick up lines. Here you can find new friends and create new partnerships. This is a funny pick up lines platform there you can fun with friends nearby or far.

    contact address: (31) 641-979389
    support@enjoyxoxo.com
    Kruitberg 5634, 1104 CA, Amsterdam Zuidoost. Netherlands

    ReplyDelete
  5. Διαβάστε περισσότερα
    Κατασκευή ιστοσελίδων, eshop και προώθηση - Η μεγαλύτερη λίστα επιτυχημένων ιστοσελίδων είναι εδώ. Ειδικευόμαστε στον σχεδιασμό και την υποστήριξη όλων των τύπων website.

    ReplyDelete
  6. do you make money from a blog
    Check out our detailed guide on how to make money blogging. This article will describe the way to start a blog through a step by step procedure.

    ReplyDelete
  7. Vitiligo Treatment
    MONOBENZONE Benoquin Vitiligo Treatment with Benoquik to Get results within 4 weeks with Benoquik 20% Cream High Quality, Fast Delivery in USA Benoquin Redues patches, makes skin natural glowing and helps to achieve uniform depigmentation, Skin Lighting agent,"

    ReplyDelete
  8. Custom sunroof installation
    we offer a wide range of new installation sunroofs, including our in-built power sunroofs which feature rear vent, one-touch open and close, key-off auto close, and integrated sun-shades that retract inside the roof of your car and can be custom made to suit your vehicle.

    ReplyDelete
  9. App developers in Bangalore
    As one of the best mobile app development companies in Bangalore, we work with a wide range of brands in all industries. We will give an awesome idea and concept that will help your company reach the next level. Our app developers in Bangalore utilize interactive mobile layouts, pitch perfect development, and appropriate call-to-action buttons.

    ReplyDelete
  10. Nice blog, thanks for sharing this blog. Benoquin cream is applied to de-pigment the skin as a vitiligo treatment , Vitligo is a skin condition of irregular patches on skin, covering about 50% of the body surface, lose colour and become whitened.

    ReplyDelete
  11. It's really nice to read and very informative. So much thanks for the sharing.

    ReplyDelete

  12. Very informative blog! Thanks for sharing.

    ReplyDelete