One Mark - java, NoSql

|
Divnesh BLOG

1 [mark] 
Q1 of 32
What is the output of the given below code?     public class Tester {
public static void main(String[] args) {
Base obj = new Derived();
obj.method(); //line 1
}
}
class Base {
public void method(int a) {
System.out.println("Base Method");
}
}
class Derived extends Base {
public void method() {
System.out.println("Derived Method");
}
}
Ans : compilation error at line 1 due to missing parameter

Q2 of 32

What is the output of the below code? public class Tester {
public static void main(String[] args) {
Base obj = new Derived();
obj.method(25);
}
}
class Base {
public static void method(int a) {
System.out.println("Base Method");
}
}
class Derived extends Base {
public static void method(int a) {
System.out.println("Derived Method");
}
}
Ans : Base Method
Q3 of 32
What is the output of the below code? 
abstract class BaseAbsClass {
public void method() {
System.out.println("BaseAbsClass Method");
}
public abstract void method2();
}
class Derived extends BaseAbsClass {
public void method2() {
System.out.println("Derived method");
}
}
public class Testing {
public static void main(String[] args) {
BaseAbsClass obj = new Derived();
obj.method2();
}
}
Ans : Derived method 
Q4 of 32
What is the output of the below code?  interface MyInterface {
void method1();
}
class MyImplementation implements MyInterface {
void method1() {
System.out.println("My Method");
}
}
public class Testing1 {
public static void main(String[] args) {
MyInterface obj = new MyImplementation();
obj.method1();
}
}
cannot reduce visibility of inherrited class 
Q5 of 32
What is the output of the below code? class Vehicle {
Vehicle() {
System.out.println("Vehicle is created");
}
}
public class Bike5 extends Vehicle {
Bike5() {
super();
System.out.println("Bike is created");
}
public static void main(String args[]) {
Bike5 b = new Bike5();
}
}
Vehicle is created Bike is created 
Q6 of 32 What is the output of the below code? 
public class Tester1 {
public static void main(String[] args) {
String s1 = "Infosys";
String s2 = "Infosys";
if (s1 == s2) {
System.out.print("Equal");
} else {
System.out.print(" UnEqual");
}
if (s1.equals(s2)) {
System.out.print(" Equal");
} else {
System.out.print(" UnEqual");
}
}
}
equal equal
Q7 of 32
If a class's methods and variables are to be made accessible only to its sub classes in different packages, what is the suitable access specifier?
protected Q8 of 32
Find the statements which are true with respect to method overriding
  • Method signature should vary (no of arguments and its type
  • Method to be invoked is decided at runtime
  • Method to be invoked is decided based on the object
  • Method can be static and private
Q9 of 32 Which of the following can be used to avoid the instantiation of a class by any code outside of the class?
declare all constructor with private access 
 Q10 of 32
What is the result of attempting to compile and run the program? 
 public class StringTest {
public static void main(String[] args) {
String s1 = "A", s2 = "a", s3 = "b";
s1.toLowerCase();
s3.replace('b', 'a');
System.out.print((s1.equals(s2)) + "," + (s2.equals(s3)));
}
}
false false
Q11 of 32
What is the result of attempting to compile and run the program? public class InfyTest {
public static void main(String[] args) {
int x, y, z;
System.out.println(x + y + z);
}
}
compilation error
Q12 of 32
Given: package p1; class A { }
package p2; import p1.A; class B extends A { } What is the output?
Complie b fails Q13 of 32
Predict the output of the below code: String value1 = "Hello";
String value2 = new String("Hello");
System.out.print(value1 == value2);
System.out.print(" ");
String value3 = value2.intern();
System.out.println(value1 == value3);
false, true
Q14 of 32
What is the output of the following code? public class SuperClass {
private void displayName() {
System.out.println("Super Class");
}
public static void main(String[] args) {
SuperClass superClass = new SubClass();
superClass.displayName();
}
}
public class SubClass extends SuperClass {
private void displayName() {
System.out.println("SubClass is a type of SuperClass");
}
}
super class
Q15 of 32
What is the output of the following code? class Person {
public Person(String name) {
System.out.println(name);
}
}
public class Student extends Person {
public Student() {
/* line 8 */ System.out.println("Student");
}
public static void main(String[] args) {
/* line 11 */ new Person("Bob");
}
}
Compile error at line 8 - due to Implicit super constructor Person() is undefined. Must explicitly invoke another constructor 
Q16 of 32
What is the output of the following code? 
 abstract class Person1 {
public final void display() {
System.out.println("Display method in Person");
}
public static void main(String[] args) {
Person1 person = new Student1();
/* line 6 */ person.display();
/* line 7 */ }
}
public class Student1 extends Person1 {
public void display() {
/* line 11 */ System.out.println("Display method in Student");
}
}
compile error at line 11  - due to Cannot override the final method from Person1
 Q17 of 32
What is the output of the following code? (Choose 2 options) 
 public class Employee {
int id = 1000; 
 protected String name = "Smith"; 
 public String role = "Software Engineer"; 
}

/* package com.mypack.demoTwo; */ 
import com.mypack.demoOne.*;

public class Trainee {
public static void main(String[] args) {
Employee emp = new Employee();
/* line 11 */ System.out.print(" " + emp.id);
/* line 12 */ System.out.print(" " + emp.name);
/* line 13 */ System.out.print(" " + emp.role);
/* line 14 */ }
}
  • 1000 Smith Software Engineer
  • Compilation error at line 11
  • Compilation error at line 12
  • Compilation error at line 13
  • Compilation error at line 14
Q18 of 32
Which of the following lines of code compile? (Choose 3 options)
  • int number = 1234;
  • float f1 = 1234.0;
  • float f2 = 1234;
  • double d3 = 1234.0;
  • long num = 1234;
Q19 of 32
What is the output of the following code? class Employee {
public void display() {
System.out.print(" display ");
}
public void print(int age) {
System.out.print(" Employee ");
}
}
public class Trainee extends Employee {
public void display(String name) {/* line 2 */ System.out.print(name);
}
public int print(int age) {/* line 5 */ 
System.out.print(" Trainee ");
return age;
}
public static void main(String[] args) {
Trainee trainee = new Trainee();
trainee.display();/* line 10 */
trainee.display("Bob");/* line 11 */
trainee.print(10);/* line 12 */ }
}
//compile error at 5  -The return type is incompatible with Employee.print(int)
Q20 of 32
What is the output of the following code? class Employee {
public static void display() {
/* line 2 */ System.out.print(" Employee ");
}
}
public class Trainee extends Employee {
public static void display() {
/* line 5 */ System.out.print(" Trainee ");
}
public static void main(String[] args) {
Employee employee = new Trainee();
employee.display();
/* line 9 */ }
}
employee
Q21 of 32
What is the output of the following code? abstract class Employee {
private void display() {
System.out.print(" Employee ");
}
}
public class Trainee extends Employee {
protected void display() {
/* line 5 */ System.out.print(" Trainee ");
}
public static void main(String[] args) {
Employee emp = new Trainee();
emp.display();
/* line 10 */ }
}
//compile error at line 10 due to private method at employee class (The method display() from the type Employee is not visible)
Q22 of 32
What is the result when the following code is compiled? public class Test {
public void method() {
for (int i = 0; i < 3; i++) {
System.out.print(i);
}
System.out.print(i);
}
}
compilation error
Q23 of 32
How many objects are eligible for garbage collection in the below code? public class Loan {
public static void main(String arg[]) {
Loan loan1 = new Loan();
Loan loan2 = new Loan();
Loan loan3 = new Loan();
Loan loan4 = new Loan();
loan1 = loan3;
loan2 = loan4;
loan3 = null;
}
}
2
Q24 of 32
What is the output of the below code snippet? import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args) {
LocalDate date = LocalDate.parse("2019-03-07");
LocalDate date1 = LocalDate.of(2019, 12, 07);
System.out.println(
date.getYear() + date1.getYear() + " , " +
date.compareTo(date1) + " , " + date1.compareTo(date));
}
}   4038, -9,9
Q25 of 32 Select all possible options among the following: Enums can be defined inside___________ (Choose 3 options)
  • An interface
  • A Class
  • A Static Context
  • A Method
Q26 of 32
Predict the output of the following code public class VarargsTest {
public static void main(String[] args) {
displayRegn("Hockey");
/* Line 1 */ displayRegn("Kho-Kho", 1, 2, 3);
}
public static void displayRegn(String nameOfSport, int... iDs) {
System.out.print(" Registration for " + nameOfSport + ":");
for (int i = 0; i < iDs.length; i++) {
System.out.print(iDs[i] + " ");
}
}
}
Registration for Hockey: Registration for Kho-Kho:1 2 3
Q27 of 32
Predict the output of the following code public class VarargsTest {
public static void main(String[] args) {
new VarargsTest().display(5, "Infosys");
new VarargsTest().display(4, "Infosys", "Limited");
}
public void display(int b, String... strings) {
System.out.print(strings[strings.length - 1] + " ");
}
}
Infosys Limited
Q28 of 32
Given the enum and the Java class public enum Day {
SUNDAY(1), MONDAY(2), TUESDAY(3), WEDNESDAY(4), THURSDAY(5), FRIDAY(6), SATURDAY(7);
private int value;
private Day(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
not possible, days will be displayed with values only
public class TestEnum {
public static void main(String[] args) {
for (Day day : Day.values()) {
}
}
} What should be placed at line 1 to get the output as shown below?  
SUNDAY-MONDAY-TUESDAY-WEDNESDAY-THURSDAY-FRIDAY-SATURDAY-
System.out.println(day.name()+"-");
Q29 of 32
Given the interface, which is the best way to create to anonymous class for this interface? public interface Fruits { void taste(); } Choose from the given below options: 
a) Fruits fruits = new Fruits () {             
public void taste() {                     System.out.println("Taste is good...");              } }; 
b) FruitsImpl fruits = new Fruits () {             
public void taste() {                    System.out.println("Taste is good...");              } }; 
c) class FruitsImpl implements Fruits {              
public void taste() {                    System.out.println("Taste is good...");              } }
Q30 of 32
Which of the following is true with respect to StringBuilder in Java? (Choose 2 options)
  • StringBuilder is non-synchronized, not thread safe
  • StringBuilder is synchronized, thread safe
  • StringBuilder is less efficient
  • StringBuilder is more efficient
Q31 of 32
Which is the correct way of comparing the contents of the below strings? String firstString = "String";
StringBuilder secondString = new StringBuilder("String");
firstString.contains(secondString) Q32 of 32
Which of the following statements are correct advantages of an immutable class?
  • Immutable objects are simple
  • Immutable classes are thread-safe, they require no synchronization
both are correct



No Sql

1.     databases is used for internet scale applications requiring large data sets, cost effective storage, and fast time to solution?

Key values store

2.     Cassandra NoSQL database provides 

high availablility and partition tollerance but strictly consistent

3.     "An application usually retrieves data by key or ID value and there is no need for complex queries. Further, there is no need for search capabilities beyond key lookup"

Key values store

4.     HBase belongs to which category of NoSQL databases?

Column family stores

5.     databases is suitable for sparsely populated tables that are too big for relational database and also related data is grouped together?

Column family stores

6.       You need to ensure you meet product delivery timelines while dispatching items ordered by customers across various locations. Which one of the following databases is most suitable for the given scenario? 

Graph based databases

7.     For representing financial details related to policy holders, which database is most suitable?

Relational databases

8.     Which category of NoSQL databases possess the following characteristics?

·        Support a nested structure

·        Support querying by multiple fields

·        Support indexing on multiple fields

·        Support sorting operations

Document oriented databases

9.     What is incorrect with respect to characteristics of NoSQL databases?

Most of the NoSQL databases do not have integrated caching facilities

10. Non Scalable : does not apply to NoSQL?

11. The eCommerce system tracks its customer's browsing patterns. For the given scenario, select the best suited data model, consistency level and read/write load

Graph, available,weight heavy.

12. Assume the checkout scenario in an online shopping site. Which of the CAP properties does this require the most?

Consistency and Partition tolerance

13. Consider the scenario where customer session data is managed by the eCommerce system. It has the following requirements:

·        faster read and write

·        need not be durable and

·        need to maintain session data for millions of online customers

14. Which category of databases is the best suitable one?

key value

15.  Map the following scenarios to the best suited database type.

A) Log Analysis
B) Catalog Display
C) Banking Transaction 
D) User preferences
E) Shortest path for product delivery

1. Document-oriented
2. Key-value
3. Column-family
4. Graph-based
5. Relational model

A-3, B-1, C-5, D-2, E-4

 

 

 


Featured Post

HTML cheetsheet

List: Link tgs Dropdown

Popular Post

(C) Copyright 2018, All rights resrved InShortView. Template by colorlib