Question

Java I need help Q1: Suppose this is a legal assignment statement: Student obj1 = new...

Java I need help

Q1: Suppose this is a legal assignment statement: Student obj1 = new Book(); what is the relationship between Student and Book?

  
1 - Student has Book as a field

  
2 - Student is a subtype of Book

  
3 - No Relationship

  
4 - Book is a subtype of Student.


Question2:

Q2: What are the types involved in this statement: Vehicle v1 = new Car();

  
1- Car

  
2- new

  
3- Vehicle and Car

  
4- v1

Q3: If two or more classes share a lot of data and behavior then the typical solution to minimize code duplication is ______________________

  
1- Encapsulation

  
2- to leave as to avoid errors

  
3- Inheritance

  
4- Defining new methods in each

Q4: If a method in a superclass has no obvious implementation then we define it as ___________

  
1- protected

  
2- static

  
3- private

  
4- abstract

Q5: _________ is a mechanism by which a call to an overridden method is resolved at run-time.

  
1- Static Binding

  
2- Call by Value

  
3- Dynamic Method Lookup

  
4- Method Overloading

Q6: When you let an object call a method to do something without knowing how that method is implemented then the process is called


1- Abstraction & object delegation

  


2- Polymorphism

  
3- Inheritance

  
4- Substitution

Q-7 Suppose we have Computer, Labtop and Desktop as classes. What is a sensible way to relate them to each other?

  
1- Computer should have Laptop and Desktop as fields

  

2- Laptop and Desktop should be subclasses of Computer

  


3- All classes should be independent of each other

  


4- Laptop and Desktop should have Computer as a field


Q8: Name the object dynamic types of car and v in these statements: Object car = new Car(); Vehicle v = new Truck();

  
1- Both are Vehicle

  
2- Both are Ineger

  
3- Car and Truck

  
4- Both are String

Q9: Assume that you see these lines of code:

Device dev = new Printer();

dev.getName();

Printer is a subclass of Device. which class must have a definition of act()for this code to compile?

  
1- Printer

  
2- String

  
3- Device

  
4- Dev

Q10: To call a superclass method foo() from a subclass we use the statement

  
1- foo().super;

  
2- super();

  
3- super.foo();

  
4- this;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1. 4-Book is a subtype of student

Q2. 1-Car

Q3. 3-Inheritance

Q4. 4-abstract

Q5. 3-Dynamic Method Lookup

Q6. 1-Abstraction & Object delegation

Q7. 2-Laptop and Desktop should be subclasses of Computer

Q8. 3-car and truck

Q9. 1-Printer

Q10. 3-super.foo()

Add a comment
Know the answer?
Add Answer to:
Java I need help Q1: Suppose this is a legal assignment statement: Student obj1 = new...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

  • For Java, 1. What is an abstract method? How is an abstract method created? 2. What...

    For Java, 1. What is an abstract method? How is an abstract method created? 2. What is an abstract class? 3. Can an object of an abstract class be instantiated? 4. Does a superclass have access to the members of subclass? Does a subclass have access to the members of the superclass? 5. How do you prevent a subclass from having access to a member of a superclass? 6. Given the following hierarchy: class Alpha{ … class Beta extends Alpha...

  • Java Mr. Dealer is trying to keep track of his new cars and used cars by...

    Java Mr. Dealer is trying to keep track of his new cars and used cars by writing a Java program. He needs your help in setting up his classes. Implement a superclass named Car that contains a price instance variable, a getPrice method, and a 1-parameter constructor. The getPrice method is a simple accessor method that returns the price instance variable’s value. The 1-parameter constructor receives a cost parameter and assigns a value to the price instance variable based on...

  • (1)     ____ is the principle that allows you to apply your knowledge of a general category...

    (1)     ____ is the principle that allows you to apply your knowledge of a general category to more specific objects.           a.       Inheritance              c.       Encapsulation           b.       Polymorphism                    d.       Override (2)     When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.           a.       fonts                      c.       class names           b.       methods                  d.       arrays (3)     By convention, a class diagram contains the ____ following each attribute or...

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

  • How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...

    How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java • Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents person First name Last name app Creates 1 student-athlete object Hometown Retinfo) 1-Displays the complete information about the student-athlete object student New attributes Maior attributes getinfo) method from the superlas person Student-athlete student's rankine Overrides the method from the superclass student Video from Professor Fisher...

  •            1.         You often need to know the inheritance ____________________ of the Java API to work...

               1.         You often need to know the inheritance ____________________ of the Java API to work with its classes and subclasses.            2.         All objects have access to the methods of the ____________ class.            3.         If two classes share some common elements, you can define those elements in a ____________.            4.         To call a constructor or method of a superclass from a subclass, you use the ____________ keyword.            5.         A class that can be inherited by another...

  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT