Java Programming OOP Questions and Answers Set 2

Java Programming OOPs

Questions 11 to 20



11.
Among these expressions, which is(are) of type String?
(a)  "0"                                                   (b)  "ab" + "cd"                                      
(c)  '0' 
(d)  Both (A) and (B) above                    (e)  (A), (B) and (C) above.
12.
Consider the following code fragment
                  Rectangle r1 = new Rectangle();
                  r1.setColor(Color.blue);
                  Rectangle r2 = r1;
                  r2.setColor(Color.red);

             After the above piece of code is executed, what are the colors of r1 and  
             r2 (in this order)?  
(a)   Color.blue
       Color.red
(b)   Color.blue
       Color.blue
(c)   Color.red
       Color.red
(d)   Color.red
       Color.blue
(e)   None of the above.
13.
What is the type and value of the following expression? (Notice the integer division)
                   -4 + 1/2 + 2*-3 + 5.0
(a)  int -5                                                (b)  double -4.5                                      
(c)  int -4                             
(d)  double -5.0                                      (e)  None of the above.
14.
What is printed by the following statement?
System.out.print("Hello,\nworld!");
(a)  Hello, \nworld!   (b)  Hello, world!                                   
(c) 
(d)  "Hello, \nworld!" (e)  None of the above.
15.
Consider the two methods (within the same class)
         public static int foo(int a, String s)
         {
           s = "Yellow";
           a=a+2;
           return a;
         }
         public static void bar()
         {
           int a=3;
           String s = "Blue";
           a = foo(a,s);
           System.out.println("a="+a+" s="+s);
         }
         public static void main(String args[])
         {
            bar();
         }
What is printed on execution of these methods?
(a)  a = 3 s = Blue                                  (b)  a = 5 s = Yellow                                           (c)  a = 3 s = Yellow
(d) a = 5 s = Blue                                   (e) none of the above.
16.
Which of the following variable declaration would NOT compile in a java program?
(a)  int var;               (b)  int VAR;            (c)  int var1;             (d)  int var_1;           (e)  int 1_var;.
17.
Consider the following class definition:
            public class MyClass
            {
            private int value;
            public void setValue(int i){ /* code */ }
            // Other methods...
            }
The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue?
(a)  value = i;                                         (b)  this.value = i;                                (c)  value == i;
(d)  Both (A) and (B) and above              (e)  (A), (B) and (C) above.
18.
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 runs.
19.
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)   Both (A) and (B) above
(e)   (a), (b) and (c) above.
20.
Consider,
              public class MyClass
              {
              public MyClass(){/*code*/}
               // more code...
               }
To instantiate MyClass, you would write?
(a)   MyClass mc = new MyClass();
(b)   MyClass mc = MyClass();
(c)   MyClass mc = MyClass;
(d)   MyClass mc = new MyClass;
(e)   The constructor of MyClass should be defined as, public void MyClass(){/*code*/}.



Answers



11.
Answer : (d)
Reason:  Strings are  "0" and "ab" + "cd" .
12.
Answer : (c)
Reason:  Both r1 and r2 are referring the same object of Rectangle class. So, finally the Color of the object is changed to red.
13.
Answer : (d)
Reason:  The execution goes on like this:
-4 + 1/2 + 2*-3 + 5.0;
-4 +  0 +  -6 +  5.0;  // integer division: 1/2 truncates .5
-10 +  5.0;  // higher type is double 5.0, so -10 is casted to double
-5.0;  //  finally, double -5.0.
14.
Answer : (c)
Reason:  The statement
System.out.print("Hello,\nworld!");
gives output as
15.
Answer : (d)
Reason:  ‘a’ value is returned from the method and so it is 5. But the string will remain same, as it is passed by value to the method.
16.
Answer : (e)
Reason:  The first character of a variable name should not be a digit.
17.
Answer : (d)
Reason:  ‘==’ is a comparison operator.
18.
Answer : (d)
Reason:  A class will always have a constructor, either provided by the user or a default constructor provided by the compiler.
19.
Answer : (e)
Reason:  A constructor
·                    Must have the same name as the class it is declared within.
·                    Is used to create objects.
·                    May be declared private.
20.
Answer : (a)
Reason:  An object is created by using a new operator.


<< 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 >>


45 comments :

  1. in 14th question ,Answer is None of these
    As Output coming is
    Hello,
    world!

    ReplyDelete
    Replies
    1. yes
      the answer (c) should to be that but not puted

      Delete
    2. then the answer is e none of the above

      Delete
    3. Hello Everybody,
      My name is Ahmad Asnul Brunei, I contacted Mr Osman Loan Firm for a business loan amount of $250,000, Then i was told about the step of approving my requested loan amount, after taking the risk again because i was so much desperate of setting up a business to my greatest surprise, the loan amount was credited to my bank account within 24 banking hours without any stress of getting my loan. I was surprise because i was first fall a victim of scam! If you are interested of securing any loan amount & you are located in any country, I'll advise you can contact Mr Osman Loan Firm via email osmanloanserves@gmail.com

      LOAN APPLICATION INFORMATION FORM
      First name......
      Middle name.....
      2) Gender:.........
      3) Loan Amount Needed:.........
      4) Loan Duration:.........
      5) Country:.........
      6) Home Address:.........
      7) Mobile Number:.........
      8) Email address..........
      9) Monthly Income:.....................
      10) Occupation:...........................
      11)Which site did you here about us.....................
      Thanks and Best Regards.
      Whats app) +917290857361
      Derek Email osmanloanserves@gmail.com

      Delete
  2. yeah, i guessed it too. but i don't know why the answer is [blank]

    ReplyDelete
  3. In question No 19.
    How constructor is used to create object.
    constructor is used to initialize the state of the object created.

    ReplyDelete
  4. very interesting post.this is my first time here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post!
    java examples

    ReplyDelete
  5. can any buddy explain me question no 17

    ReplyDelete
    Replies
    1. it should be (b). You need this.value = i to assign i to the object.

      Delete
  6. I surprised with the analysis you made to make this particular publish incredible. Wonderful activity! 0 E 4thTaylor, TX 76574 MLS # 2178510

    ReplyDelete
  7. Are you tired of seeking loans and Mortgages,have you been turned down constantly By your banks and other financial institutions,We offer any form of loan to individuals and corporate bodies at low interest rate.If you are interested in taking a loan,feel free to contact us today,we promise to offer you the best services ever.Just give us a try,because a trial will convince you.What are your Financial needs?Do you need a business loan?Do you need a personal loan?Do you want to buy a car?Do you want to refinance?Do you need a mortgage loan?Do you need a huge capital to start off your business proposal or expansion? Have you lost hope and you think there is no way out, and your financial burdens still persists? Contact us (gaincreditloan1@gmail.com)

    Your Name:...............
    Your Country:...............
    Your Occupation:...............
    Loan Amount Needed:...............
    Loan Duration...............
    Monthly Income:...............
    Your Telephone Number:.....................
    Business Plan/Use Of Your Loan:...............
    Contact Us At : gaincreditloan1@gmail.com
    Phone number :+44-75967-81743 (WhatsApp Only)

    ReplyDelete
  8. will you explain question no.12 that how it works .
    class Color{
    static String blue="Color.blue";
    static String red="Color.red";
    }
    class Rectangle{
    String color;
    public void setColor(String color){
    this.color=color;
    System.out.println(color);
    }
    public static void main(String[] args) {
    Rectangle r=new Rectangle();
    r.setColor(Color.blue);
    Rectangle r2=r;
    r2.setColor(Color.red);

    }
    }
    output:
    Color.blue
    Color.red

    ReplyDelete
  9. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. java training in Chennai|| j2ee training in Chennai

    ReplyDelete
  10. Welcome to Joy Fredickson loan Organization, we are formed to help people in needs of helps,such as financial help. So if you are going through financial difficulty or you are in any financial mess,and you need funds to start up your own business or you need loan to settle your debt or pay off your bills,start a nice business, or you are finding it hard to obtain capital loan from local banks,contact us today via email: joyfredickson55@yahoo.com or WhatsApp number: +2348078800681
    INFORMATION NEEDED.
    Your Name...
    Last name...
    SEX..
    AGE...
    Country......
    PURPOSE OF LOAN........
    YOUR MONTHLY INCOME....
    Loan Amount needed....
    Loan Duration....
    Cell Phone Number....

    Thank you.

    ReplyDelete
  11. This blog is very useful for me and thanks for sharing
    Java Online Training Hyderabad

    ReplyDelete
  12. I found your this post while searching for information about blog-related research ... It's a good post .. keep posting and updating information.
    Ghana passport online

    ReplyDelete

  13. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....


    Best Tableau online training in Hyderabad


    Tableau online training in Hyderabad


    Tableau training in Hyderabad

    ReplyDelete
  14. good information ...Mulesoft ESB Training in HyderabadBest Mulesoft Training institutes in Hyderabad Mulesoft Training realtime trainers in Hyderabad, Mulesoft Training course fee in Hyderabad, Mulesoft Training course details, online Mulesoft Training institutes in Hyderabad, online Mulesoft Training courses in Hyderabad, Mulesoft Training centers in Hyderabad, learn Mulesoft Training , Mulesoft Training videos, Mulesoft Training materials, Mulesoft Training study materials, Mulesoft Training corporate trainers in Hyderabad, best Mulesoft Training classes in Hyderabad online Mulesoft Training classes in Hyderabad, top Mulesoft Training institutes in Pune, leading Mulesoft Training institutes in Hyderabad, Mulesoft Training course contents, Mulesoft Training course structure, online Mulesoft Training

    ReplyDelete
  15. I really appreciate u for creating this website. It really helps in my academic

    ReplyDelete
  16. Thanks for posting this valuable information about java and i am very eager to read you blog...
    Data science training in hyderabad
    Tableau Training in Hyderabad

    ReplyDelete
  17. Thanks for posting such an amazing article keep bloggging...
    DataScience Training In Hyderabad

    ReplyDelete
  18. nice! thanks for sharing such a good information please keep blogging..
    Tableau Training In Hyderabad

    ReplyDelete
  19. What is the answer of 14 question. C. Means what?

    ReplyDelete
  20. Someone Sometimes with visits your blog regularly and recommended it in my experience to read as well. The way of writing is excellent and also the content is top-notch. Thanks for that insight you provide the readers!
    cs作业 代写

    ReplyDelete
  21. urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748


    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748


    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748


    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748


    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748
    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    urgently in need of Kidney donors with the sum of $500,000.00,Email: healthc976@gmail.com
    Wat-sap: +91 8754313748

    ReplyDelete
  22. The good information about java . Newly joind IT People it can be useful.
    thanks for sharing .
    JAVA Training in hyderabad

    ReplyDelete
  23. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    http://chennaitraining.in/sap-mm-training-in-chennai/
    http://chennaitraining.in/sap-mss-training-in-chennai/
    http://chennaitraining.in/sap-pi-training-in-chennai/
    http://chennaitraining.in/sap-pm-training-in-chennai/
    http://chennaitraining.in/sap-pp-training-in-chennai/
    http://chennaitraining.in/sap-ps-training-in-chennai/
    http://chennaitraining.in/sap-qm-training-in-chennai/

    ReplyDelete
  24. TESTIMONY ON HOW I GOT MY LOAN FROM A GENUINE FINANCE COMPANY LAST WEEK. Email for immediate response: drbenjaminfinance@gmail.com

    I am Mrs,Leores Jazbel by name, I live in United State Of America, who have been a scam victim to so many fake lenders online between November last year till July this year but i thank my creator so much that he has finally smiled on me by directing me to this new lender who put a smile on my face this year 2020 and he did not scam me and also by not deceiving or lying to me and my friends but however this lending firm is BENJAMIN LOAN INVESTMENTS FINANCE (drbenjaminfinance@gmail.com) gave me 2% loan which amount is $900,000.00 united states dollars after my agreement to their company terms and conditions and one significant thing i love about this loan company is that they are fast and unique. {Dr.Benjamin Scarlet Owen} can also help you with a legit loan offer. He Has also helped some other colleagues of mine. If you need a genuine loan without cost/stress he his the right loan lender to wipe away your financial problems and crisis today. BENJAMIN LOAN INVESTMENTS FINANCE holds all of the information about how to obtain money quickly and painlessly via Call/Text: +1(415)630-7138 Email: drbenjaminfinance@gmail.com

    When it comes to financial crisis and loan then BENJAMIN LOAN INVESTMENTS FINANCE is the place to go please just tell him I Mrs. Leores Jazbel direct you Good Luck.......................

    ReplyDelete
  25. Thanks, this is generally helpful.
    Still, I followed step-by-step your method in this Java online training
    Java training

    ReplyDelete


  26. Cool way to have financial freedom!!! Are you tired of living a poor life, here is the opportunity you have been waiting for. Get the new ATM BLANK CARD that can hack any ATM MACHINE and withdraw money from any account. You do not require anybody’s account number before you can use it. Although you and I knows that its illegal,there is no risk using it. It has SPECIAL FEATURES, that makes the machine unable to detect this very card,and its transaction can’t be traced .You can use it anywhere in the world. With this card,you can withdraw nothing less than $4,500 a day. So to get the card,reach the hackers via email address : besthackersworld58@gmail.com or whatsapp him on +1(323)-723-2568

    ReplyDelete
  27. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    java online course
    Visit us: Java Online Training

    ReplyDelete
  28. Your info is really amazing with impressive content..Excellent blog.
    Visit us: Java Online Training Hyderabad
    Visit us: Core Java Online Course
    Visit us: java course

    ReplyDelete
  29. I am super excited today, all thanks Lapo Micro Finance for giving me a loan. I was deceived several times trying to get a loan until I came across Lapo Micro Finance who provided me with a loan worth $ 23,000 to care for my sick child. If you need a real lender today contact Lapo .Contact email: lapofunding960@gmail.com
    Whatsapp +447883183014

    ReplyDelete
  30. Hi, Thank you for this informative blog, I have just started to learn java course and this blog is really informative for me. Thank you for this blog!

    ReplyDelete
  31. Thank you so much, nice to see such a post to write such a beautiful post, and when I saw this post of yours, I was very happy to see its design and when I read it, I love to appreciate it. Because those who write such a beautiful post must get credit for it.
    Dating Girls Service Gurugram
    Dating Girls Gurugram
    Gurgaon New Hotel
    Enjoy your Night

    ReplyDelete
  32. Ping-here : @killhacks - Telegram/ICQ
    @peeterhacks - Wickr/Skype

    Leads-Pros-Fullz

    Fullz-Pros SSN+DOB+DL
    Fullz High-Cresdit-Scores
    CC+C.V.V with SSN Info Fullz
    Dumps-Pin-Codes (101/202)
    Fullz-Business-E.I.N
    Tax-Return-Filling-Fullz
    Fullz-For SBA/PUA/UI-Filling
    Premium-Fullz For applying-loans

    Fullz-available in Bulk-quantity
    Genuine-stuff Fresh-Spammed
    Within-Mins-Delivery
    Will-be-replaced If anything-Invalid

    Tools&Tutorials available-too for Hacking+Carding+Spamming+Cracking
    Mai-lers-Senders-C.panels-Shells-Web-mailers
    Bru-tes, Dorks, R.A.T's, RDP's, Vir-uses
    2021/2022-Fr**d Bi**e
    Complete Kali-Linux/Python Courses
    WA/FB-Hacking-Methods/Key-loggers
    Packages-are-also-available For Learning-Purpose

    TG - @leadsupplier
    ICQ - 752822040
    Wickr/Skype - @peeterhacks

    For-More-Info Hit me up

    ReplyDelete
  33. There is essentially no limit to the benefits of striking visuals on your garment with iron-on printed fabric labels

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. This is a very good article, we have told about PowerDirector on our site Powerdirector App

    ReplyDelete
  36. In "Java Programming OOP Questions and Answers Set 2," understanding object-oriented principles can be likened to designing a clothing line, such as the red one clothing. Just as each piece in a collection has its unique attributes and methods, classes in Java encapsulate data and behavior, making programming both structured and creative.



    ReplyDelete