Classes and Objects

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

8. Looking at the code above, how many objects are created? * 0 1 2 3

1

public class Objects { public static void main(String[ ] args) { Circle c = new Circle( ) ; Circle c1 = c; c1.setRadius(5); c.setRadius(10); System.out.pringln(c1.getRadius()); } } class Circle { int radius; Circle( ) { radius = 1 } public int getRadius( ) { return radius; } public void setRadius(int radius) { this.radius = radius; } } 7. Looking at the code above, what is printed? * 1 5 10 2

10

1. What is the relationship between a class and an object? * An object is comprised of many classes A class is a blueprint for an object An object is a blueprint for a class A class is comprised of many objects

A class is a blueprint for an object

4. Given a class called Cat and an object of type Cat called fluffy, which of the following would be the way to call a static method called clean()? * Cat.clean() fluffy.clean() void clean() Cat fluffy.clean()

Cat.clean()

5. Which of the following describes instance variables? (Select more than one) * Describes the state of the object Each object has its own copies All objects of one class share one copy The type of an instance variable must be set when the variable is declared

Describes the state of the object Each object has its own copies The type of an instance variable must be set when the variable is declared

2. What is encapsulation? * The idea of hiding the implementation details from the users of the class The idea of one class getting methods and variables from a parent class The idea of a method chosen at run-time based on the type of the object calling it The idea of many objects being created from one class

The idea of hiding the implementation details from the users of the class

3. Given a class called Cat and an object of type Cat called fluffy, which of the following would be the way to call an instance method called clean()? * Cat.clean() fluffy.clean() void clean() Cat fluffy.clean()

fluffy.clean()

9. Which of the following is a valid header to a getter method? * int getNum() void getNum() int getNum(int x) void getNum(int x)

int getNum()

6. Given a class named Cat, which of the following are valid constructor headers? * public Cat() public Cat(String name) public void Cat() public void Cat(String name)

public Cat() public Cat(String name)


Kaugnay na mga set ng pag-aaral

Micro Chapter 13: Labor Markets, Poverty, & Income Distribution, Micro: Chapter 14, Chapter 15: International Trade and Trade Policy

View Set

Anatomy: posterior and lateral leg (8.2)

View Set

Holistic Health EAQ: Perfusion Custom Quiz

View Set