Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Name the option. Question 1 Classes that are derived from an existing class through inheritance have a has-a relationship. Question 1 options: True False Question

Name the option.

Question 1

Classes that are derived from an existing class through inheritance have a "has-a" relationship.

Question 1 options:

True
False

Question 2

A class can only be used as a superclass once.

Question 2 options:

True
False

Question 3

A subclass can extend only one superclass.

Question 3 options:

True
False

Question 4

A subclass can refer to...

Question 4 options:

the private instance variables of the superclass

the private instance methods of the superclass

the public instance methods of the superclass

none of the above

Question 5

What can an abstract class contain?

Question 5 options:

constructors, instance variables, instance methods, abstract methods, static methods, static variables

constructors, instance variables, instance methods, abstract methods,

abstract methods, static methods, static variables

instance variables, instance methods, abstract method

Question 6

What is the use of the keyword super in a subclass?

Question 6 options:

It provides access to the constructor of the superclass.

It provides access to an instance method of the superclass.

It provides access to a public instance variable of the superclass.

All of the above.

None of the above

Question 7

What is the purpose of a constructor in a subclass.

Question 7 options:

To initialize value of the subclasses' private and public instance variable through assignment statements (eg. this.x = 1)

To initialize the value of the subclasses' public and private instance variables and the superclasses' private and public instance variables through assignment statements. (super.x = 1; this.y = 2)

To use a super constructor to initialize the value of the superclasses' instance variables.

To initialize value of the subclasses' private and public instance variable through assignment statements (eg. this.x = 1) and use a super constructor to initialize the value of the superclasses' instance variables.

Question 8

Abstract classes can not be instantiated.

Question 8 options:

True
False

Question 9

Which of the following is a correct implementation of polymorphism. Note, object B extends object A.

Question 9 options:

B obj1 = new A();

A ob1 = new A();

B obj1 = new B();

A obj1 = new B();

Question 10

Interfaces differ from Abstract class because:

Question 10 options:

a class can implement many interfaces, but can only extend one abstract class

abstract classes create a hierarchy but interfaces do not

interfaces can only contain abstract methods and no implementations

all of the above

Question 11

Given this code snippet,

public class Person { public String name; public Person(String name) { System.out.println(name); this.name = name; } public void printName() { System.out.println(this.name); } } public class Miner extends Person { public Miner(String name) { super(name); } }

what will this program print?

Person somePerson = new Person("Bob"); Miner mikeTheMiner = new Miner("Mike"); mikeTheMiner.printName();

Question 11 options:

This code causes an error.

Mike Mike Bob

Bob Mike Mike

Bob

Bob Mike Bob

Question 12

Based on this code snippet

public class Shape { public String getShapeName() { return "Shape"; } } public class Rectangle extends Shape {} public class Square extends Rectangle {} public class Oval extends Shape { public String getShapeName() { return "Oval"; } } public class Circle extends Oval { public String getShapeName() { return "Circle"; } }

what does this program output?

Shape shape1 = new Shape(); Shape shape2 = new Rectangle(); Shape shape3 = new Square(); Shape shape4 = new Circle(); System.out.println(shape1.getShapeName()); System.out.println(shape2.getShapeName()); System.out.println(shape3.getShapeName()); System.out.println(shape4.getShapeName());

Question 12 options:

Shape Rectangle Rectangle Circle

Shape Shape Shape Shape

Shape Shape Shape Circle

This code will error

Shape Rectangle Square Circle

Shape Rectangle Rectangle Oval

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

here) and other areas you consider relevant.

Answered: 1 week ago