Interview Questions → JAVA → Java Questionnaire II

Java Questionnaire II













class ClassWithOverrideMethods
{
	public void printchar()
	{		
		System.out.println("this is the method without parameter");
	}

	public void printchar(char str)
	{
		System.out.println(str);
	}
}

class MainClass
{
	public static void main(String args[])
	{
		ClassWithOverrideMethods clsObject = new ClassWithOverrideMethods();
		clsObject.printchar();
		clsObject.printchar('a');
	}
}












class Shape
{
	public void draw()
             {
             	System.out.println("I can be of any shape");
	}
}
  
class Rectangle extends Shape
{
	public void draw()
             {
             	System.out.println("My shape is rectangular");	
	}
}

class MainClass
{
	public static void main(String args[])
             {
              	Rectangle r=new Rectangle();
                          r.draw();
	}
}












class thisKeywordDemo
{
	int a=100;
	
	void disp()
	{
		int a=10;
		System.out.println("a"+a);
		System.out.println("a"+this.a);
	}

	public static void main(String args[])
	{
		thisKeywordDemo t=new thisKeywordDemo();
		t.disp();
	}
}












class superKeywordDemo
{
   void disp()
   {
       System.out.println("I m inside parent class");
   }
}
class SubClass extends superKeywordDemo
{
   void disp()
   {
       System.out.println("I m inside child class");
   }

   void CallBothMethods()
   {
      disp(); 
      super.disp();
   }
   
}

class MainClass
{
   public static void main(String aa[])
   {
      SubClass s = new SubClass(); 
      s.CallBothMethods();
   }
}












class Outer
{
   class Inner 
   {
      void disp()
      {
         System.out.println("I m inside Inner class disp");
      }
   }
   void CallInnerClass()
   {
      Inner n = new Inner();
      n.disp();
   }
   
   
}

class MainClass
{
   public static void main(String aa[])
   {
      Outer o = new Outer();
      o.CallInnerClass();
   }
}








try
{}
catch(FileNotFoundException e)
{}
























String ABC = "test";
ABC = "2344";








class BaseClass
{
	public final void Display()
	{
		System.out.println("This is the method of base class");
	}
}

class ChildClass extends BaseClass
{	
	public void Display()
	{
		System.out.println("This is the method of child class");
	}
}

class MainClass
{
	public static void main(String args[])
	{		
		ChildClass c = new ChildClass();
		c.Display();
	}
}
























Posted By  -  Karan Gupta


Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250