Java Questionns
Java Questionns
Java Questionns
What is a variable?
A. count
B. $count
C. count27
D. 67coun
What is Java’s character type, and how does it differ from the character type used by some
Show the for statement for a loop that counts from 1000 to 0 by –2.
Using two separate statements, show how to declare an object called counter of a class
called MyCounter.
Show how a method called myMeth( ) is declared if it has a return type of double and has
What is this?
If all objects of a class need to share the same variable, how must you declare that variable?
To make a member accessible by only other members of its class, what access modifier
must be used?
Create a varargs method called sum( ) that sums the int values passed to it. Have it return
the result. Demonstrate its use.
Does a superclass have access to the members of a subclass? Does a subclass have access to
Create a subclass of TwoDShape called Circle. Include an area( ) method that computes
the area of the circle and a constructor that uses super to initialize the TwoDShape portion.
How do you prevent a method from being overridden? How do you prevent a class from
being inherited?
Explain how inheritance, method overriding, and abstract classes are used to support
polymorphism.
A class that contains at least one abstract method must, itself, be declared abstract.
True or False?
Explain the two ways that the members of a package can be used by other packages.
“One interface, multiple methods” is a key tenet of Java. What feature best exemplifies it?
How many classes can implement an interface? How many interfaces can a class implement?
The finally block is the last bit of code executed before your program ends. True or False?
Even though console input and output is text-based, why does Java still use byte streams for
this purpose?
How can you convert a numeric string such as "123.23" into its binary equivalent?
Write a program that copies a text file. In the process, have it convert all spaces into hyphens.
Use the byte stream file classes. Use the traditional approach to closing a file by explicitly
calling close( ).
What does the read( ) method of InputStream return when the end of the stream is
reached?
Reader and Writer are at the top of the ____________ class hierarchies
How does Java’s multithreading capability enable you to write more efficient programs?
When creating a runnable object, why might you want to extend Thread rather than
implement Runnable?