Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Which option suits best along with reason JAVA CODE MCQ

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Which option suits best along with reason JAVA CODE MCQ

     
     
     
    1. package utils;
    2.
    3. public class Repetition {
    4. public static String twice(String s) { return s + s; }
    5. }
    and given another class Demo:
     
    1. // insert code here
    2.
    3. public class Demo {
    4. public static void main(String[] args) {
    5. System.out.println(twice("pizza"));
    6. }
    7. }
    Which code should be inserted at line 1 of Demo.java to compile and run Demo
    to print "pizzapizza"?
    A. import utils.*;
    B. static import utils.*;
    C. import utils.Repetition.*;
    D. static import utils.Repetition.*;
    E. import utils.Repetition.twice();
    F. import static utils.Repetition.twice;
    G. static import utils.Repetition.twice;


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    571
    My Mood
    Sleepy
    Thanks
    9
    Thanked 84 Times in 78 Posts

    Default Re: Which option suits best along with reason JAVA CODE MCQ

    What happened when you've tried it?

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Which option suits best along with reason JAVA CODE MCQ

    C:\Users\Mayank\Documents\revision\Demos.java:7: package utils does not exist
    import static utils.Repitition.twice;
    ^
    C:\Users\Mayank\Documents\revision\Demos.java:7: static import only from classes and interfaces
    import static utils.Repitition.twice;
    ^
    C:\Users\Mayank\Documents\revision\Demos.java:15: cannot find symbol
    symbol : method twice(java.lang.String)
    location: class Demos
    System.out.println(twice("pizza"));
    ^
    3 errors

    I am getting these errors

  4. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    571
    My Mood
    Sleepy
    Thanks
    9
    Thanked 84 Times in 78 Posts

    Default Re: Which option suits best along with reason JAVA CODE MCQ

    Quote Originally Posted by mayankpant View Post
    package utils does not exist
    That's bad.

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Which option suits best along with reason JAVA CODE MCQ

    If you have a question about your assignment you should ask it.

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM
  2. Replies: 10
    Last Post: April 21st, 2013, 09:28 AM
  3. Replies: 3
    Last Post: February 20th, 2012, 09:11 AM
  4. Replies: 1
    Last Post: March 31st, 2010, 09:42 PM