JAVA LANGUAGE
a) A class can have many methods but only one constructor.
b) A constructor can be used instead of fields to represent the data inside a class.
c) A constructor wastes memory in the computer so it should be used sparingly.
d) A constructor is a special method that creates an object and initializes its state.
e) Constructors are considered bad programming style and should be avoided.
f) A constructor is the code that is called when you use the ‘new’ keyword.
class Table {
Person student = new Person();
public void getStudent() {
return student;
}
// other methods go here…
}
public ClassOne(int alpha) {
this.alpha = alpha;
this.beta = 0;
}
public ClassOne(int alpha, int beta) {
this.alpha = alpha;
this.beta = beta;
}
class X {
private int m = 48;
}
class Y extends X {
void methodOfY() {
System.out.println(m);
}
}
public class Mystery {
public static void main(String[] args) {
String one = “two”;
String two = “three”;
String three = “1”;
int number = 20;
sentence(one, two, 3);
sentence(“eight”, three, number / 2);
}
public static void sentence(String three, String one, int number){
System.out.println(one + “ times “ + three + “ = “ + (number * 2);
}
}
a) Car jaguar = new Vehicle();
b) Vehicle ferrari = new Car();
c) Motorcycle ducati = new Vehicle();
d) Motorcycle goldwing = new Car();
15) In Java, single text characters are
represented by what data type ?
---------->character
16)
d) A constructor is a special method that creates an object and initializes its state.
f) A constructor is the code that is called when you use the ‘new’ keyword.
17) Person student = new Person();
It cannot be initalised like this because this piece of
code will never be called
18)
public ClassOne(int alpha) {
this.alpha = alpha;
this.beta = 0;
ClassOne(alpha, beta);
}
19) Why is the code below showing a compile time
error?
Private fields cannot be inherited
20) Why is the code below showing a compile time
error?
Private fields cannot be inherited
21)
three times two = 6
1 times eight = 20
22)b) Vehicle ferrari = new Car();
Thanks, PLEASE COMMENT if there is any concern.
JAVA LANGUAGE In Java, single text characters are represented by what data type? Which of the...
Java please answer A to I please dont type the answer on
paper please use the computer
A. Explain why alpha cannot be accessed by other
members of its class.
B. In the program, how can you determine the type of
access modifier?
C. Describe the differences and similarities of beta
and gamma in program, within the context of access specifiers and
class member accessibility.
D. Explain how objects, a and b, are passed to the
method.
E. Why...
Implement the following class in Java: Class name: People Constructor Summary: public People (String name) Methods: public People(String name) public void setName(String name) public String getName() Class name: Truck Constructor Summary: public Truck (int licensePlate, int onBoard, People people) Initially, the truck does not contain any on board the vehicle. If the number of people on board the vehicle is a negative number, the value of onBoard should be stored as zero. Methods: public int getLicensePlate() Returns license plate of...
Required in Java. Thank you.
1. Create a base class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1 in the textbook and in LMS). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double). Give your classes...
What is the output of running class C? The three Java classes are in separate Java files in the same directory (or in the same package). class A { public AO { System.out.println("The default constructor of A"); } // end A constructor } // end class A class B extends A { public BCString s) { System.out.println(s); } // end B constructor } // end class B public class C { public static void main(String[] args) { B b =...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...
Java CSE 135 Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does it override? Which methods does it add? public class Question{ . . . public void display() { System.out.println(text); }} public class ChoiceQuestion extends Question{ . . . public void display() { super.display(); for (int i = 0; i < choices.size(); i++) { int choiceNumber = i + 1; System.out.println(choiceNumber + ": " + choices.get(i)); } }} public class QuestionDemo{ public static void main(String[] args)...
Java: Create a class called Vehicle with the following features: a. It has three private data members (instance variables): one is the manufacturer’s name (String manufacturer), the second is the number of cylinders in the engine (int cylinder), and the third is the owner (Person owner). The class Person is described above. b. It has three constructors, a no-argument constructor, a constructor with three parameters, and a copy constructor. The no-argument constructor will set the manufacturer to “None”, cylinder to...
Draw a UML class diagram (with associations) to show the design of the Java application. public class OOPExercises { public static void main(String[] args) { //A objA = new A(); B objB = new B(); System.out.println("in main(): "); //System.out.println("objA.a = "+objA.getA()); System.out.println("objB.b = "+objB.getB()); //objA.setA (222); objB.setB (333.33); //System.out.println("objA.a = "+objA.getA()); System.out.println("objB.b = "+objB.getB()); } } public class A { int a = 100; public A() {...
DESCRIPTION: The range of integers that can be represented in Java using a primitive data type is only from-263 to 263-1. What if we need to manipulate integer values beyond this range? In this assignment you will write a HugeInteger class which is able to represent arbitrar- ily large integer numbers. This class must implement arithmetic operations on integers such as addition, subtraction, multiplication, division and comparison. You have to implement this class without using Java predefined classes, unless specified...