Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question :You have been given following code

public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;

public void display() {
System.out.println("Name: " + name + " Major: " + major);
}

public boolean isFullTime() {
return fulltime;
}
}
Which line of code initializes a student instance?

 :You have been given following code
1. Student student1;
2. Student student1 = Student.new();
3. Access Mostly Uused Products by 50000+ Subscribers
4. Student student1 = Student();




Correct Answer : Get Lastest Questions and Answer :







Question : Which of the following will print current time?

 : Which of the following will print current time?
1. System.out.print(new LocalTime()-now);
2. System.out.print(new LocalTime());
3. Access Mostly Uused Products by 50000+ Subscribers
4. System.ouLprint(LocalTime.today());
5. None of the above.





Correct Answer : Get Lastest Questions and Answer :
Explanation: The LocalTime is an interface, so we can't use new keyword with them. So options A and C
are incorrect. To get current time we can call now method on LocalTime interface. So option
C is correct. Option D is incorrect as there is no method called today as in LocalTime
interface







Question : Given the code fragment:
String name = "Spot";
int age = 4;
String str ="My dog " + name + " is " + age;
System.out.println(str);

And
StringBuilder sb = new StringBuilder();

Using StringBuilder, which code fragment is the best potion to build and print the following string
My dog Spot is 4

A. sb.append("My dog " + name + " is " + age);
System.out.println(sb);

B. sb.insert("My dog ").append( name + " is " + age);
System.out.println(sb);

C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age);
System.out.println(sb);

D. sb.append("My dog ").append( name ).append(" is " ).append(age);
System.out.println(sb);


 : Given the code fragment:
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D






Correct Answer : Get Lastest Questions and Answer :






Related Questions


Question : What is the proper way to defined a method that take two int values and returns their sum as an int value?

 : What is the proper way to defined a method that take two int values and returns their sum as an int value?
1. int sum(int first, int second) { first + second; }
2. int sum(int first, second) { return first + second; }
3. Access Mostly Uused Products by 50000+ Subscribers
4. int sum(int first, int second) { return first + second; }

5. void sum (int first, int second) { return first + second; }




Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}

What is the result?
 : You have been given following code
1. 8
2. 9
3. Access Mostly Uused Products by 50000+ Subscribers
4. 10
5. Compilation fails




Question : You have been given following code

public class SampleClass {
public static void main(String[] args) {
AnotherSampleClass asc = new AnotherSampleClass();
SampleClass sc = new SampleClass();
sc = asc;
System.out.println("sc: " + sc.getClass());
System.out.println("asc: " + asc.getClass());
}
}

class AnotherSampleClass extends SampleClass {
}

When you execute it, what will be printed ?


 : You have been given following code
1. sc: class Object asc: class AnotherSampleClass
2. sc: class SampleClass asc: class AnotherSampleClass
3. Access Mostly Uused Products by 50000+ Subscribers
4. sc: class AnotherSampleClass asc: class AnotherSampleClass





Question :You have been given following code

public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;

public void display() {
System.out.println("Name: " + name + " Major: " + major);
}

public boolean isFullTime() {
return fulltime;
}
}
Which line of code initializes a student instance?

 :You have been given following code
1. Student student1;
2. Student student1 = Student.new();
3. Access Mostly Uused Products by 50000+ Subscribers
4. Student student1 = Student();





Question : Which of the following will print current time?

 : Which of the following will print current time?
1. System.out.print(new LocalTime()-now);
2. System.out.print(new LocalTime());
3. Access Mostly Uused Products by 50000+ Subscribers
4. System.ouLprint(LocalTime.today());
5. None of the above.






Question : Given the code fragment:
String name = "Spot";
int age = 4;
String str ="My dog " + name + " is " + age;
System.out.println(str);

And
StringBuilder sb = new StringBuilder();

Using StringBuilder, which code fragment is the best potion to build and print the following string
My dog Spot is 4

A. sb.append("My dog " + name + " is " + age);
System.out.println(sb);

B. sb.insert("My dog ").append( name + " is " + age);
System.out.println(sb);

C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age);
System.out.println(sb);

D. sb.append("My dog ").append( name ).append(" is " ).append(age);
System.out.println(sb);


 : Given the code fragment:
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D