Example of overloading

Assignment Help JAVA Programming
Reference no: EM13742534

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

Reference no: EM13742534

Questions Cloud

Journalize entries for disposal of equipment : Beka Company owns equipment that cost $50,000 when purchased on January 1, 2008. It has been depreciated using the straight-line method based on estimated salvage value of $5,000 and an estimated useful life of 5 years.
Management communication in the past decade : The purpose of this short research paper is to ensure proper understanding and application of APA style as required in all Ashford courses. Using the Ashford Online Library, develop an annotated bibliography on one of the following factors that ha..
Barriers interfering with the communication : Can you identify and reduce the likelihood of barriers interfering with the communication. Give examples. Use at least one resource to support your key points. Respond to at least two of your fellow students' posts with your response to some of th..
Intercultural communication competence help you personally : Is it important for you to achieve a certain level of intercultural communication competence. Would enhanced intercultural communication competence help you personally. Professionally. Academically. Include examples in your submission and use at l..
Example of overloading : Implement in different classes and that have the same number and type of parameters - Inheritance models the IS-A relationship, in which the objects of the subclass are also objects of the superclass - Different classes and that have the same number ..
Designing the job : "Designing the Job" According to your textbook Nelson and Quick, (2015) Results Only Work Environment (ROWE) allows employees to work completely flexible schedules based on their ability to meet measurable goals. Employees are allowed to come and ..
Summarize importance of political change took place in india : Summarize the importance of the political, economic, and social changes took place in India after independence.
A comparative development approach of brain asymmetry : Prepare a review on topic A COMPARATIVE DEVELOPMENT APPROACH OF BRAIN ASYMMETRY: ZEBRAFISH (Danio rerio) AND MEDAKA (Oryzias latipes)
Write an essay on the george herbert walker bush : Write an essay on the George Herbert Walker Bush. each vocabulary should be one slide. for each vocabulary, brief explain what it is.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd