Document
Document
System.out.print("Enter
your name: ");
o String name =
scanner.nextLine();
o
System.out.print("Enter
your age: ");
o int age =
scanner.nextInt();
o
System.out.println("Hello,
" + name + "! You are " +
age + " years old.");
o scanner.close();
o }
o }
4. Question: Consider the following code snippet:
static void main(String
argument[]) {
System.out.println("This gets
printed"); }
o public Dog(){
o this.breed = "Lab";
o this.name = "Dog";
o this.age = 0;
o }
o }
o double radius;
o public Circle(String
color, double radius) {
o super(color);
o this.radius = radius;
o }
o}
o I am a dog
System.out.println("This is
a final method");
o }
o private void
myMethod2(){}
o }
o class Child extends Parent
{
o // Compile-Time Error:
Cannot override a final
method
o //public void
myMethod() { }
o // Compile Time Error:
cannot access private
method
o // public void
myMethod2(){}
o }
Drawable{
o @Override
o public void draw(){
o
System.out.println("Drawing
circle");
o }
o }
26. Question: Is the following code snippet valid?
Explain your answer.
public abstract class
MyAbstractClass {
public void doSomething() {
//doing something }
public static void main(String
args[]) {
MyAbstractClass obj = new
MyAbstractClass();//Line 1
obj.doSomething(); //Line
2
}
}
System.out.println("Doing
something");
• }
• }
o}
System.out.println("intValue is:
" + intValue);
}
}