Professional Documents
Culture Documents
Opp TH
Opp TH
Opp TH
class Human {
String name;
int age;
void speak() {
System.out.println("Speaking...");
}
}
class Man extends Human {
void shave() {
System.out.println("Shaving...");
}
}
interface GrandFather {
void showGrandFather();
}interface GrandMother {
void showGrandMother();
}
public void showGrandFather() {
System.out.println("This is Grand-Father.");
}
public void showGrandMother() {
System.out.println("This is Grand-Mother.");
}
public void showGrandChild() {
System.out.println("This is Grand-Child.");
}
public static void main(String[] args) {
GrandChild gc = new GrandChild();
gc.showGrandFather();
gc.showGrandMother();
gc.showGrandChild();
}
}
Read the following code carefully to answer the question:
interface Assignment
{
void marks();
}
class Final_Assignment
{
}
Illustrate the difference between the interface and class.
Construct a relationship between Assignment and Final_Assignment to override the mentioned
method.
finalAssignment.marks();
}
}
class A{
try{
String a=null;
a=”Hi”;
}
catch(Exception e)
{
System.out.println(e);
}
}
Recall the hierarchy of the mechanism with examples by examining the above code.
class A {
public A() {
try {
String a = null;
a = "Hi"; } catch (Exception e) {
System.out.println(e);
}
}
ct1.setMarks(20);
System.out.println("Marks after setting to 20: " + ct1.getMarks());
}
}