Introduction to objects, Everything is an Object, Controlling program flow.
Questions
- What
is an Object? What is a class?
- Which
from the following are access specifiers:
- private
- local
- default
- protected
- public
- There
are some differences between Interface
and Abstract Class? If yes,
enumerate some of them.
- Which
are the parts of a method?
- What
is wrong in the following code?
class Shape
public
double getArea()
}
- What javadoc tag is used to describe the method parameters?
- Based
on operator precedence order the following operator types:
Arithmetic (and
shift)
Relational
Conditional
(ternary)
Unary
Assignment
- What
will be the results of the following code?
.
int s = 0;
for (int i = 0; i < 10; ++i)
System.out.println "Result: " + s);
Problems
- Create
a switch statement that prints a message for each case, and put the switch
inside a for loop that tries each case. Put a
break after each case and test it, then remove the breaks and see what happens.
- Write
a program to transform a decimal number in a binary one.
- Write
a program to compute all prime numbers less than a given number.
Initialization & cleanup
Questions:
- What
is the role of the constructor?
- What
is the meaning of the default constructor?
- Does
the java syntax support constructor overloading?
- How
can you distinguish the overloaded methods?
- Find
and explain the errors from the following code.
class Person
public
Person(String firstName, String lastName)
public
Person(String firstName, String lastName,
int age)
public
void print()
.
}
- When
are initialized the static members of a class?
- What will be the result of the
execution for the following code:
public class TestOverloading
private
void print(double d)
private
void print(int i)
private
void print(char c)
public
static void main(String[] args)
}
- When
and why should we use finalize() method?
Problems
- Create a
class with two (overloaded) constructors and call the second constructor
inside the first one.
- Create a
class with a static String field that is initialized at the point
of definition, and another one that is initialized by the static block.
Add a static method that prints both fields.
Test:
- Which is
the order of initialization of members within a Java class?
- Create a
class that creates a two dimensional array of integers named lincol. Initialize each array element with the sum of
its indices. For example, lincoln should be
initialized to , or . Print out all
the values stored in the lincoln array.