• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Answer choices that are too close to call. What would you choose?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some questions with answers, two of which seem too close to call. And what is more chatgpt 3.5 answers are at odds with 4.0 so I am confused even more.
Q1 - Which code fragment can be inserted at line nl to enable the code to print true?
A. public int equals (Student s) {
return studentName.compareTo(s.studentName);
}
B. protected boolean equals (Object obj) {
return true;
}
C. boolean equals (Object obj) {
if (obj = null) {
return false;
}
if (!(obj instanceof Student)) {
return false;
}
D. Student obj1 = (Student) obj
return this.studentName = obj1.studentName;
public boolean equals (Object obj) throws NullPointerException {
return true;
is correct answer A or C?
But C is correct only if following corrected code is used
@Override
public boolean equals(Object obj) {
   if (this == obj) {
       return true;
   }
   if (obj == null || getClass() != obj.getClass()) {
       return false;
   }
   Student student = (Student) obj;
   return this.studentName.equals(student.studentName);
}
So which option should be considered right in above question.

Q2. Given the information:
Derby database driver is available in the classpath.
The derby database is accessible with derby_url, derby_userName, and derby_password.
and the code fragment:
public static void main(String[] args) throws SQLException,
ClassNotFoundException {
String mySQLdriver = <<fully qualified path to the MySQL driver>>;
String derby_url = // URL of the derby driver
String derby userName = // user name of the derby driver
String derby password = // password of the derby driver
Class.forName (mySQLdriver);
Connection con = DriverManager.getConnection(derby url, derby userName, derby password);
}
Which statement is true?
A. Only Derby driver is loaded. Derby DBMS connection is established.
B. The program throws an exception at runtime.
C. The program results a compilation error
D. Both the drivers MySQL and Derby are loaded. Derby DBMS connection is established.
A and B both seem to correct but A seems better choice. Am I correct?

Q3.
. Given:
A class Employee implements Serializable { private static final String LOCATIONID private int empid;
}
=
"LOC-01":
private transient String password="password";
public Employee (int empid, String password) { this.empid = empid;
this.password = password;
public void displayEMPDetails() {
System.out.println(empid + ":" + password + ":" + LOCATIONID);
and the code fragment:
ObjectOutputStream outputStream = new ObjectOutputStream("data.dat"); outputStream.writeObject (new Employee (100, "nopassword"));
ObjectInputStream inputStream = new ObjectInputStream("data.dat"); Employee restoredEMP = (Employee) inputStream.readObject(); restoredEMP.displayEMPDetails();
What is the result?
A 100:nopassword: LOC-01
B A compilation error occurs.
C 100:null:LOC-01
is it C or should it be A?  C seems to be better choice explanation - When the Employee object is deserialized, the password field, which is marked as transient, will not be restored to its original value ("nopassword") and will instead have its default value (null).
So, the output will be: 100:null:LOC-01

Q4.
Messages.properties:
greet = Welcome!
Messages fr_FR.properties:
greet Bienvenue
Given the code fragment:
public class Test {
}
public static void main(String[] args) {
// Line nl
Locale.setDefault(locale);
ResourceBundle resource = ResourceBundle.getBundle ("Messages"); System.out.print (resource.getString("greet"));
Which two code fragments, when inserted at Line nl independently, enable the code to print Bienvenue?
A. Locale locale = Locale.FRANCE;
B. Locale locale = new Locale( Locale.FRENCH, Locale.FRANCE);
C. Locale locale = new Locale("fr_FR");
D. Locale locale = Locale.FRENCH;
E. Locale locale = new Locale("FR");


chatGPT 3.5 seems to suggest A and C (Locale locale = new Locale("fr_FR");) which seem to be correct.
but what about A and B Locale locale = new Locale( Locale.FRENCH, Locale.FRANCE);  >> not sure if using Locale twice is correct specially Locale,FRANCE

any experts want to chime in?





 
 
Marshal
Posts: 79956
396
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please indent your code and use the code button, as I did in the quoted text below. Your original code was illegible. What's more, I don't know where n1 is, and I think the answer comes in two parts:-
  • 1: Ignore ChatGPT
  • 2: None is correct as the code stands.
  • Jaan Wick wrote:Here are some questions with answers, two of which seem too close to call. And what is more chatgpt 3.5 answers are at odds with 4.0 so I am confused even more.
    Q1 - Which code fragment can be inserted at line nl to enable the code to print true?
    A.
    B.
    C.
    D.
    is correct answer A or C?
    But C is correct only if following corrected code is used

    So which option should be considered right in above question. . . .

    A returns an int; since I can't see anywhere with == 0, I can't see how that would be correct.
    B won't compile because you are trying to override equals() with too restrictive access.
    C won't compile because some paths of execution don't return a boolean. The second version you posted might compile, but it is probably not a correct implementation because the use of getClass() is too restrictive. Also it can't cope with the situation where the object passed has null entered as a name field. Remember, the equals() method's general contract includes that it always returns the same result, which means it is not allowed to throw any exceptions.
    D looks very confusing; I think you have copied it wrongly. It looks like methods inside methods, which is prohibited.

    Please post the second question in some fashion that we can read it, and you might get an answer there. too.
     
    Sheriff
    Posts: 4641
    582
    VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:1: Ignore ChatGPT


    My thinking is don't trust ChatGPT (or any other AI resource) unless you know enough about the subject to be able to determine if the answer is correct or not - AI systems frequently hallucinate.

    The responses from the chatbots are generally presented as authoritative and sound plausible/convincing, even when they are making things up.
     
    Campbell Ritchie
    Marshal
    Posts: 79956
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sounds like some people: have to give an answer even when they have no idea.
    I went via Manchester on Wednesday and, as usual, I got lost finding my way from Piccadilly Station to Victoria Station. One person told me earnestly that Piccadilly is the more important and bigger station. Quite “plausible/convincing”, particularly since I had come from Piccadilly Station ten minutes previously.
     
    So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic