Ask Java Expert


Home >> Java

Question 1

In object oriented programming, every object...
(A) is an attribute of another object
(B) is an instance of a class
(C) inherits from a class
(D) has recursive methods
Which one of the above is correct? _______________________

Question 2

Select the correct statement or statements regarding object oriented programming in Java:
(A) Inheritance models the IS-A relationship, in which the objects of the subclass are also objects of the superclass.
(B) The number of methods in a superclass is always higher than in each of its subclasses.
(C) Two subclasses of the same superclass always have the same number of methods.
(One of more correct answer is possible)

Answer(s): ______________________

Question 3

Select the correct answer/s regarding visibility in Java. When an attribute (instance variable) is defined as private in a class:
(A) it can be accessed only once in the program
(B) it can be accessed and modified only from methods of that class
(C) it can be accessed and modified only from private methods of that class
(D) it can be accessed and modified only from methods of that class and its subclasses
(E) it can be accessed and modified only from methods of that class and its superclass
(F) it can be accessed but it cannot be modified
(One of more correct answer is possible)

Answer(s): ______________________

Question 4

Which of the following sentences about constructors in Java are correct?
(A) The return type void must be included in the declaration of a constructor
(B) A class can have several constructors
(C) Constructors are used to create objects (instances) of a class
(D) Constructors need to receive at least one argument
(E) Constructors are special methods that cannot be overloaded
(One of more correct answer is possible)

Answer(s): ______________________

Question 5

Given two points p1 and p2 represented in the bidimensional space by coordinates x and y, the length of the line that connects these two points (i.e. the distance between these two points) is given by the formula:

d = √(x2 - x1)2 + (y2 - y1)2

where x1 and y1 represent the coordinates of p1, and x2 and y2 represent the coordinates of p2.

The following two Java classes, Point and Line, represent bidimensional points and straight lines that connect two points.

public class Point {
private double x = 0;
private double y = 0;

public Point(int a, int b) {
x = a;
y = b;
}

public double getX() {
return x;
}

public double getY() {
return y;
}
}

public class Line {
private Point p1;
private Point p2;

public Line (Point firstPoint, Point secondPoint) {
p1 = firstPoint;
p2 = secondPoint;
}
}

We want to implement the method length() in the class Line. This method calculates the distance of the two points that are connected by a straight line. Would the following implementations of length() be correct?

NOTE: The method Math.sqrt(x) calculates the square root of x and the method Math.pow(x,2)calculates x squared.
(Please mark a "X" for the correct answer)
public double length() {
return Math.sqrt(Math.pow(p2.getX()-p1.getX(),2)
+ Math.pow(p2.getY()-p1.getY(),2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.getX()-p1.getY(),2)
+ Math.pow(p2.getY()-p1.getX(),2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.x-p1.x,2)
+ Math.pow(p2.y-p1.y,2));
}
Answer: YES ( ) NO ( )

public double length() {
return Math.sqrt(Math.pow(p2.x-p1.y,2)
+ Math.pow(p2.y-p1.x,2));
}
Answer: YES ( ) NO ( )

Question 6

Given the following class:
public class Student {
static int counter = 0;
int id;

public Student() {
id = counter;
counter++;
}

public static void main(String[] args){
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
System.out.println(s1.id + "" + s2.id + "" + s3.id);
System.out.println(s1.counter + "" + s2.counter + "" + s3.counter);
}
}

PART A) Which is the result printed on screen of executing:
System.out.println(s1.id + "" + s2.id + "" + s3.id);
(A) 000
(B) 001
(C) 012
(D) 111
(E) 123
(F) 222
(G) 234
(H) 333
Answer: __________________________

PART B) Which is the result printed on screen of executing:
System.out.println(s1.counter + "" + s2.counter + "" + s3.counter);
(A) 000
(B) 001
(C) 012
(D) 111
(E) 123
(F) 222
(G) 234
(H) 333
Answer: __________________________

Question 7

Given MyClass and YourClass classes, as shown below, what line should replace //...[Here]... in YourClass?
public class MyClass {
private int a;
public MyClass (int a) {
this.a = a;
}
}

public class YourClass extends MyClass {
private int b;
public YourClass (int a, int b) {
//...[Here]...
this.b = b;
}
}

(A) this.a = a;
(B) MyClass(a);
(C) super(a);
(D) YourClass(a);
(E) a=a;

Answer: ___________________________

Question 8

Which of the following options is an example of overloading:

(A) Two methods with the same name that are implemented in the same class, and that have the same number and type of parameters

(B) Two methods with the same name that are implemented in different classes and that have the same number and type of parameters

(C) Two methods with the same name that are implemented in the same class, and that have the same number of parameters but of different types

(D) Two methods with the same name that are implemented in different classes, and that have the same number of parameters but of different types

(E) One method implemented in one class, and another method with the same name, number and type of parameters implemented in a class that inherits from the first one

Java, Programming

  • Category:- Java
  • Reference No.:- M91300864
  • Price:- $30

Guranteed 24 Hours Delivery, In Price:- $30

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As